我对蟒蛇3.8有问题。我正在使用特金特。我试图做一个简单的UI(我正在做一些测试,实际上我正在学习tkinter)这是代码:### importing libraries ###import tkinter from tkinter import *import os, glob### importing libraries ###### creating tk and the principal frame ###tk = Tk()tk.title("calculator") f1 = Frame(tk, bg="white", height=1200, width=1200) f1.pack() #### creating tk and the principal frame #### #### initializing the ui #### f1.mainloop() #### initializing the ui####### creating buttons ###bruh = tkinter.Button(f1,background="white", text="moltiplica")### creating buttons ###### adding buttons and setting the position ###bruh.pack(padx=30,pady=1)### adding buttons and setting the position ###问题是按钮没有出现,当我关闭应用程序时,控制台打印出这个东西:File "c:/Users/MS/### importazione delle librerie ###.py", line 21, in <module>bruh = tkinter.Button(f1,background="white", command="ciao", text="moltiplica")File "C:\Users\MS\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 2645, in __init_ Widget.__init__(self, master, 'button', cnf, kw)File "C:\Users\MS\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 2567, in __init__self.tk.call(_tkinter.TclError: can't invoke "button" command: application has been destroyed
1 回答
千巷猫影
TA贡献1829条经验 获得超7个赞
您正在呼叫 .主循环创建一个无限循环,直到您关闭程序。将所有内容放在它之前,否则它将在您关闭应用程序(应用程序已被销毁)后执行。Tkinter 通过调用其中一个包管理器来初始化它的 UI,在你的情况下。mainloop()
pack()
添加回答
举报
0/150
提交
取消