Python Tkinter window management and settings (2): basic window settings

Python crawler, data analysis, website development and other case tutorial videos are free to watch online

https://space.bilibili.com/523606542

Add title

# 设置窗口标题 
root.title("title")

Add icon

# 设置图标,以OneDrive图标为例,必须是以 .ico 为后缀的图标文件,放于同目录下。 
root.iconbitmap("OneDrive.ico")

Set background

# 设置背景色,可以用英文名,也可以用十六进制表示的颜色。 
root["background"] = "#00ffff"

Complete code

# 导入模块,取别名 
import tkinter as tk 
# 实例化一个窗体对象 
root = tk.Tk() 
# 设置窗口的大小长宽为300x300出现的位置距离窗口左上角+150+150 
root.geometry("300x300+150+150") 
# 进入消息循环,显示窗口 
root.mainloop() 
# 设置窗口标题 
root.title("title") 
# 设置图标,以OneDrive图标为例,必须是以 .ico 为后缀的图标文件,放于同目录下。 
root.iconbitmap("OneDrive.ico") 
# 设置背景色,可以用英文名,也可以用十六进制表示的颜色。 
root["background"] = "#00ffff"
# 进入消息循环,显示窗口 
root.mainloop()

Effect demonstration

Python GUI programming: the basic settings of the window

Guess you like

Origin blog.csdn.net/m0_48405781/article/details/114239635