[英]python print command in same open window not in prompt
Ok so i am trying my hand in python and ran into a issue with this little app i am trying to put together. 好的,所以我尝试使用python并遇到我试图组合的这个小应用程序的问题。 I am trying to have a window open on run and ask for a keyword input, then match that input to a any line in a file.
我试图在运行时打开一个窗口,并要求输入关键字,然后将该输入与文件中的任何行匹配。 I enter the input and press show, but the results don't show or show in the prompt.
我输入了输入并按显示,但结果未显示或未在提示中显示。 I need to have the results show in the open window.
我需要在打开的窗口中显示结果。 possibly on a new row and column that is created when the show button is pressed.
可能在按下显示按钮时创建的新行和新列上。 so the results show in the window only, I am on a ubuntu based system.
因此结果仅显示在窗口中,我在基于ubuntu的系统上。 Here is my app .py file
这是我的应用程序.py文件
#!/usr/bin/python
# -*- coding: utf-8 -*-
# sets the name settings
from Tkinter import *
class App(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
# runs the script to get full
# list of programs for matching
#subprocess.call(["listcmnd.sh"])
# create the application
myapp = App()
# sets the e1 variable
e1 = Entry(myapp)
# checks keyword agianst
# programs in the sam.txt file
import re
keyword = open("results/program_files/sam.txt", "r")
for line in keyword:
if re.match("str(text)", line):
print line,
# prints results of keyword entry match
def show_entry_fields():
print("Program Name: %s" % (e1.get()))
# gives the output of findings
from Tkinter import *
# asks for search critiria
text = Label(myapp, text="Keyword: ").grid(row=0)
# displays the buttons for getting
# results and closing program
Button(myapp, text='Quit', command=myapp.quit).grid(row=3, column=0, sticky=W, pady=4)
Button(myapp, text='Show', command=show_entry_fields).grid(row=3, column=1, sticky=W, pady=4)
# prints results of keyword entry match
def show_entry_fields():
print("Program Name: %s" % (e1.get()))
# displays the text entry field
e1.grid(row=0, column=1)
#
# here are method calls to the window manager class
#
myapp.master.title("Program Search Tool")
myapp.master.maxsize(1000, 400)
# start the program
myapp.mainloop()
ok so i made a few alterations to the main script but still outputs results to terminal and not in the open window 好的,所以我对主脚本进行了一些更改,但仍将结果输出到终端,而不是在打开的窗口中
Here is new code alterations 这是新的代码更改
#!/usr/bin/python
# -*- coding: utf-8 -*-
# sets the name settings
from Tkinter import *
class App(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
# runs the script to get full
# list of programs for matching
#subprocess.call(["listcmnd.sh"])
# create the application
myapp = App()
# sets the e1 variable
e1 = Entry(myapp)
# checks keyword agianst
# programs in the sam.txt file
import re
keyword = open("results/program_files/sam.txt", "r")
for line in keyword:
if re.match("get()(text)", line):
print line,
# prints results of keyword entry match
def show_entry_fields():
print("Program Name: %s" % (e1.get()))
# asks for search critiria
# displays the text entry field
e1.grid(row=0, column=1)
text = Label(myapp, text="Program Name: ")
text.grid(row=3, column=0)
# displays the buttons for getting
# results and closing program
Button(myapp, text='Quit', command=myapp.quit).grid(row=4, column=0, sticky=W, pady=4)
Button(myapp, text='Show', command=show_entry_fields).grid(row=2, column=0, sticky=W, pady=4)
#
# here are method calls to the window manager class
#
myapp.master.title("Program Search Tool")
myapp.master.maxsize(1000, 1000)
myapp.master.minsize(50, 50)
# start the program
myapp.mainloop()
What you should do is create a label (or maybe create it before and update it) in function 您应该做的是在函数中创建一个标签(或者可能在之前创建并更新它)
def show_entry_fields():
Additional remarks: 附加说明:
you import Tkinter several times 您多次导入Tkinter
you also define def show_entry_fields(): twice 您还定义了def show_entry_fields():两次
text = Label(myapp, text="Keyword: ").grid(row=0)
doesn't work. 不起作用。 You must write:
您必须写:
text = Label(myapp, text="Keyword: ")
text.grid(row=0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.