2 回答
TA贡献1900条经验 获得超5个赞
你应该设置一个函数,并在函数中执行此操作command
import tkinter
def press():
global to_download
if to_download:
print(to_download)
window.destroy()
window = tkinter.Tk()
window.configure(background="grey90")
window.title("Downloader")
window.geometry("300x300")
window.resizable(False, False)
entry = tkinter.Entry(window)
entry.place(x=70,y=68)
entry.configure(highlightbackground="grey90")
button = tkinter.Button(window, text="Download",
command=press, highlightbackground="grey90")
button.place(x=110,y=120)
window.mainloop()
TA贡献1820条经验 获得超9个赞
此行可能不小心从原始代码中省略。它应该插入到 press 函数中 if 语句之前:
to_download = entry.get()
以下是完整的代码:
import tkinter
def press():
global to_download
to_download = entry.get()
if to_download:
print(to_download)
window.destroy()
window = tkinter.Tk()
window.configure(background="grey90")
window.title("Downloader")
window.geometry("300x300")
window.resizable(False, False)
entry = tkinter.Entry(window)
entry.place(x=70,y=68)
entry.configure(highlightbackground="grey90")
button = tkinter.Button(window,
text="Download",
command=press,
highlightbackground="grey90")
button.place(x=110,y=120)
window.mainloop()
添加回答
举报