我正在尝试创建一个执行特定计算的 tkinter gui。我创建了一个窗口来要求输入以进行计算。但是,每次我运行我的代码时,都会弹出 2 个窗口而不是一个。有没有办法在我运行我的代码时自动关闭空白窗口,这样用户只会看到要求输入的窗口。为简单起见,我更改了所有按钮以关闭应用程序。import numpy as npimport pandas as pdfrom datetime import datetimeimport tkinter as tkimport tkinter.ttk as ttkimport tkinter.messageboximport blpapiimport pdblpcon = pdblp.BCon(timeout=5000)con.start()s= ttk.Style()s.theme_use('xpnative')root =tk.Tk()root.title("Vega Requirement Application")root.geometry("600x400")ticker_var= tk.StringVar()volume_var= tk.StringVar()def close(): root.destroy()def clear_all(): root.destroy()def vega_calculation(): root.destroy()ticker_label = ttk.Label(root, text='Bloomberg Ticker:',font=('calibre',10,'normal'))ticker_entry = ttk.Entry(root, textvariable = ticker_var,font=('calibre',10,'normal'))volume_label = ttk.Label(root, text='Volume:',font=('calibre',10,'normal'))volume_entry = ttk.Entry(root, textvariable = volume_var,font=('calibre',10,'normal'))run_btn = ttk.Button(root, text = 'Calculate', command = vega_calculation, width = 13)close_btn = ttk.Button(root, text= 'Close App', command = close, width =13)clear_btn = ttk.Button(root, text= 'Clear table', command = clear_all, width=13)ticker_label.grid(row=0,column=0)ticker_entry.grid(row=0,column=1)volume_label.grid(row=1,column=0)volume_entry.grid(row=1,column=1)run_btn.grid(row=0,column=2)close_btn.grid(row=1, column=2)clear_btn.grid(row=0, column =4)root.mainloop()
1 回答
守候你守候我
TA贡献1802条经验 获得超10个赞
以下两行将创建一个实例,因为它们执行时Tk()没有实例:Tk()
s = ttk.Style() # create an instance of Tk() if there is none
s.theme_use('xpnative')
将这两行移动到之后,root = tk.Tk()以便它使用已经创建的实例Tk():
root = tk.Tk()
s = ttk.Style() # use existing instance of Tk(), root
s.theme_use('xpnative')
添加回答
举报
0/150
提交
取消