1.Python GUI之tkinter介绍

时间:2022-07-25
本文章向大家介绍1.Python GUI之tkinter介绍,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
from tkinter import Tk

#1.显示窗口
my_window=Tk()

#标题
my_window.title("我的窗口")

#设置窗口居中
#获取整个屏幕大小
screen_width, screen_height = my_window.maxsize()

#设置窗口大小
width=240
height=480
# align_str="%dx%d" % (width, height)
align_str="%dx%d+%d+%d" % (width, height,(screen_width-width)/2,(screen_height-height)/2)

#设置窗口的宽、高
my_window.geometry(align_str)

#设置窗口是否可以缩放 True表示可缩放 False表示不可缩放
my_window.resizable(width=True, height=False)

my_window.mainloop()