[英]Tkinter GUI does not respond
我是编程新手,我正在尝试运行一个程序,该程序要求用户提供一个目录,他们会将文件移动到该目录。
import tkinter as tk
from tkinter import filedialog, ttk
class Unzip():
def __init__(self):
# initialising the screen name, size title
root = tk.Tk()
root.geometry('650x550')
root.title("Move Files")
root.resizable(0, 0)
root.configure(bg='#002060')
# Initialising the frame to insert our widget
top_frame = tk.Frame(root, bg='#002060')
button_top = tk.Frame(root, bg='#002060')
button_bottom = tk.Frame(root, bg='#002060')
footer_frame = tk.Frame(root, bg='#002060')
top_frame.pack(side='top', fill='both')
button_top.pack(side='top', fill='both')
button_bottom.pack(side='top', fill='both')
footer_frame.pack(side='bottom', fill='both')
# Setting the title name
label_title = tk.Label(top_frame, text='Move Files', font='Arial 36 bold', fg='#948a54',
bg='#002060', pady=60)
label_title.pack(side='top')
# call button to get output file
output_file = ttk.Button(button_bottom, text='Choose location to save files', width=25, command=self.output_path)
output_file.pack(side='left', padx=(120, 10), pady=10)
root.mainloop()
# Get output directory
def output_path(self):
self.output_file_dir = filedialog.askdirectory()
if __name__ == '__main__':
Unzip()
问题是当您运行程序并尝试运行output_file
按钮时,程序将没有响应。 我决定使用self
因为我希望它可以被我想要创建的其他实例方法访问,这些方法将使用目录output_path
。
那么你到底在期待什么? 你的程序确实有响应,但它不应该对信息做任何事情。 尝试
def output_path(self):
self.output_file_dir = filedialog.askdirectory()
print(self.output_file_dir)
你看到会发生什么吗? 也许此链接中的示例 2 可以帮助您: https : //www.programcreek.com/python/example/95888/tkinter.filedialog.askdirectory
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.