Tkinter. My first GUI program

Create GUI window

Of course the one used is tkinter

#导入tkinter模块
#在安装python时就已经安装了该模块,所以不用自己安装
from tkinter import *
root=Tk()#root是自定义的Tk对象名称,也可以取其他名称
root.mainloop()#该方法可以让程序继续执行,同时进入等待处理窗口事件

Operation result:
Insert picture description here
Such a window seems too small, what properties does the window have?

Window properties

Insert picture description here

from tkinter import *
root=Tk()
root.title('萤火虫')#窗口标题
root.geometry('300x400+200-200')#宽x高+左边距-下边距(+x -x +y -y左右上下)
root.maxsize(500,500)#最大拖拽窗口500 500
root.minsize(50,50)#最小拖拽窗口
root.configure(bg='pink')#背景颜色
root.iconbitmap('1.ico')#更改图标 1.ico是我图标的位置
root.mainloop()

operation result:
Insert picture description here

Reorganize

from tkinter import *
from tkinter import messagebox#弹出提示信息
root=Tk()
root.title('萤火虫')
root.geometry('500x300+200+200')
root.configure(bg='pink')#背景为粉色

confirm_button=Button(root)#添加button按钮
confirm_button['text']="点我试一下"#按钮文本
confirm_button.pack()
def confirm(e):
    messagebox.showinfo("提示","Hello tkinter")
confirm_button.bind("<Button-1>",confirm)#<Button-1>点击鼠标左键
root.mainloop()

Operation result:
Insert picture description here
Click on the "Try it" button and a prompt box will pop up.

tk control summary

Insert picture description here
Source of this image: https://www.cnblogs.com/tynam/p/8779319.html

Guess you like

Origin blog.csdn.net/qq_44862120/article/details/107906606