tkinter窗口仅在第一次执行时有效

时间:2019-06-14 14:56:33

标签: python python-3.x tkinter

我一直在尝试构建一个tkinter窗口,该窗口具有一些Check按钮,一个图像和一个按钮。我使用Spyder IDE,并且在我打开Spyder并首次运行它时,代码工作正常。但是,当我尝试再次执行时,图像不会出现,并且显然窗口也不会被我创建的按钮破坏。我的代码有问题吗?

这是我的代码:

import tkinter as tk                              # GUI configuration
from PIL import ImageTk, Image


# Window to select the analysis actions
config_window = tk.Tk()

config = { # Dictionnary with variables that control what the algorithm will do
     "EDIT_FILES":     tk.BooleanVar(),
     "RMS_ANALYSE":    tk.BooleanVar(),
     "WATERFALL_FFT":  tk.BooleanVar()
}
config_window.title('Analysis settings')

label = tk.Label(config_window, text='Please check the boxes corresponding to the operations you would like to do',\
                 background='red')
label.grid(row=0, sticky='n')

tk.Checkbutton(config_window, text='Edit the files created from the sensor measurements', \
               variable=config["EDIT_FILES"]).grid(row=1, sticky='w')
tk.Checkbutton(config_window, text='RMS analysis', \
               variable=config["RMS_ANALYSE"]).grid(row=2, sticky='w')
tk.Checkbutton(config_window, text='FFT analysis', \
               variable=config["WATERFALL_FFT"]).grid(row=3, sticky='w')

image = Image.open("logo.png").resize((220,80), Image.ANTIALIAS)
logo = ImageTk.PhotoImage(image, size=10)
im_label = tk.Label(image=logo)
im_label.image = logo
im_label.grid(row=4, sticky='w')

tk.Button(config_window, text='Ok', width=10, command=config_window.destroy).grid(row=4, sticky='e')

config_window.mainloop()

0 个答案:

没有答案