【发布时间】:2015-03-01 17:05:44
【问题描述】:
当用户单击按钮时,我将如何创建一个新窗口(仍需要创建)?我已经取出了一些代码来缩短它。我需要创建一个按钮,当他们点击该按钮时,会打开一个新窗口。我没有创建按钮,因为按钮必须链接到新窗口。请帮忙
My imports...
class App:
def __init__(self, master):
self.master = master
# call start to initialize to create the UI elemets
self.start()
def start(self):
self.master.title("E-mail Extranalyser")
self.now = datetime.datetime.now()
tkinter.Label(
self.master, text=label01).grid(row=0, column=0, sticky=tkinter.W)
# CREATE A TEXTBOX
self.filelocation = tkinter.Entry(self.master)
self.filelocation["width"] = 60
self.filelocation.focus_set()
self.filelocation.grid(row=0, column=1)
# CREATE A BUTTON WITH "ASK TO OPEN A FILE"
# see: def browse_file(self)
self.open_file = tkinter.Button(
self.master, text="Browse...", command=self.browse_file)
# put it beside the filelocation textbox
self.open_file.grid(row=0, column=2)
# now for a button
self.submit = tkinter.Button(
self.master, text="Execute!", command=self.start_processing,
fg="red")
self.submit.grid(row=13, column=1, sticky=tkinter.W)
def start_processing(self):
#code here
def browse_file(self):
# put the result in self.filename
self.filename = filedialog.askopenfilename(title="Open a file...")
# this will set the text of the self.filelocation
self.filelocation.insert(0, self.filename)
root = tkinter.Tk()
app = App(root)
root.mainloop()
【问题讨论】:
-
我有,但没有多大帮助
-
其实链接的问题回答得很好。只需创建一个
Toplevel窗口。 “我没有创建按钮,因为按钮必须链接到新窗口”是什么意思?