python - Tkinter 命令函数调用
问题描述
我是python新手,自从我开始使用python以来,Tkinter中的命令调用对我来说从来没有用过我已经尝试了所有方法并且我取消了刹车但它仍然不起作用我在这里看到了相关主题但他们没有这里对我不起作用是一个简单的代码,我尝试过指出当我单击按钮时没有任何反应,那么问题出在哪里?
from tkinter import *
if __name__ == "__main__":
root = Tk()
root.geometry("400x400")
compile_button=Button(root,text="Compiler",command=root.quit)
compile_button.pack()
解决方案
root.mainloop()
在你的末尾添加__main__
。所以 GUI 开始工作。有关更多信息,请查看此问题。- 也可以使用
root.destroy
方法。
整个代码:
from tkinter import *
if __name__ == "__main__":
root = Tk()
root.geometry("400x400")
compile_button=Button(root,text="Compiler", command=root.quit)
compile_button.pack()
root.mainloop()
推荐阅读
- java - LeanFT 和 selenium webdriver 屏幕截图 - 在之间切换
- html - 背景图像对于桌面屏幕大小来说太小了?
- java - JavaFX PropertyValueFactory 无法从位于不同包中的类接收属性
- swift - spritekit 如何选择性地缩放节点
- python - 如何使用 joblib 和 scikitlearn 并行交叉验证
- javascript - redux-thunk 中间件 multiple => Syntex
- python - django webapp 和 django-rest-framework 可以一起生活吗?
- asp.net-mvc - Javascript 发布请求回调,从 .NET MVC 控制器重定向
- .net-core - .NET Core:代码合同方法目前已关闭?
- multithreading - 使用 goroutine 运行同一程序的另一个实例?