【发布时间】:2015-04-11 16:13:37
【问题描述】:
好的,所以我正在尝试使用 python,但在我尝试组合的这个小应用程序中遇到了问题。我试图在运行时打开一个窗口并要求输入关键字,然后将该输入与文件中的任何行匹配。我输入输入并按显示,但结果未显示或显示在提示中。我需要在打开的窗口中显示结果。可能在按下显示按钮时创建的新行和列上。所以结果只显示在窗口中,我在一个基于 ubuntu 的系统上。这是我的应用程序 .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()
好的,所以我对主脚本做了一些改动,但仍然将结果输出到终端,而不是在打开的窗口中
这是新的代码改动
#!/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()
【问题讨论】:
标签: python user-interface tkinter window