[英]Tkinter GUI does not respond
I'm new to programming and I'm trying to run a program that asks a user for a directory which which they will move their files to.我是编程新手,我正在尝试运行一个程序,该程序要求用户提供一个目录,他们会将文件移动到该目录。
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()
The problem is that when you run the program and try to run the output_file
button, the program will not be responding.问题是当您运行程序并尝试运行
output_file
按钮时,程序将没有响应。 I decided to use the self
because I wanted it to be accessible to other instance methods that I want to create that will use the directory output_path
.我决定使用
self
因为我希望它可以被我想要创建的其他实例方法访问,这些方法将使用目录output_path
。
So what exactly are you expecting?那么你到底在期待什么? Your program does respond, but it is not supposed to do anything with the information.
你的程序确实有响应,但它不应该对信息做任何事情。 Try
尝试
def output_path(self):
self.output_file_dir = filedialog.askdirectory()
print(self.output_file_dir)
Do you see what happens?你看到会发生什么吗? Maybe example 2 from this link can help you: https://www.programcreek.com/python/example/95888/tkinter.filedialog.askdirectory
也许此链接中的示例 2 可以帮助您: https : //www.programcreek.com/python/example/95888/tkinter.filedialog.askdirectory
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.