Python 按钮doesen';t与tkinter一起出现(3.8)

Python 按钮doesen';t与tkinter一起出现(3.8),python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我对python 3.8有一个问题。 我用的是tkinter。 我试着做一个简单的ui(我在做一些测试,实际上我正在学习tkinter) 代码如下: ### importing libraries ### import tkinter from tkinter import * from tkinter import * import os,glob ### importing libraries ### ### creating tk and the principal frame ###

我对python 3.8有一个问题。 我用的是tkinter。 我试着做一个简单的ui(我在做一些测试,实际上我正在学习tkinter) 代码如下:

### importing libraries ###
import tkinter 
from tkinter import *
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 ###
问题是按钮没有出现,当我关闭应用程序时,控制台会打印出以下内容: 文件“c:/Users/MS/##########.py”,第21行,bruh=tkinter.Button(f1,background=“white”,command=“ciao”,text=“moltiplica”)文件“c:\Users\MS\AppData\Local\Programs\Python\Python38\lib\tkinter\uu init.py”,第2645行,在init\uuuu小部件中“C:\Users\MS\AppData\Local\Programs\Python38\lib\tkinter\uuuuu init\uuuuuu.py”,第2567行,在uuu init\uuuuu self.tk.call中(
_tkinter.TclError:无法调用“按钮”命令:应用程序已被销毁

您正在调用的是
mainloop()
。mainloop将创建一个无限循环,直到您关闭程序。请将所有内容放在它之前,否则它将在您关闭应用程序后执行(应用程序已被销毁).Tkinter通过调用其中一个包管理器来初始化它的UI,在您的情况下,
pack()

这是否回答了您的问题?在代码之前的一个eplanation语句通常就足够了,作为注释编写:一个hashtag#。对于更长的注释,您可以使用docstring三重引号“”。谢谢大家!我解决了这个问题!(感谢刚刚学过的东西)