本文章向大家介绍Tkinter 之Place布局,主要包括Tkinter 之Place布局使用实例、应用技巧、基本知识点总结和需要注意事项
效果图:
源码及注释
import tkinter
win = tkinter.Tk() #构造窗体
win.title("坐公交也用券-按钮位置")#标题
'''
400x200+300+310
分别对应:
400宽度
200高度
300(x坐标,即横坐标,作用是设置出现的程序界面位于屏幕的哪个位置[左或者右])
310(y坐标,即纵坐标,作用是设置出现的程序界面位于屏幕的哪个位置[上或者下])
'''
win.geometry("400x200+300+310") #设置窗口的大小,具体方法在上面的注释已说明
button = tkinter.Button(win, text="右下角", width=20, height=1)
button.pack() #加载到窗体
button.place(x=230, y=140) #设置坐标(以程序界面大小为基准)
button1 = tkinter.Button(win, text="中间", width=20, height=1)
button1.pack() #加载到窗体
button1.place(x=100, y=90) #设置坐标(以程序界面大小为基准)
button2 = tkinter.Button(win, text="左上角", width=20, height=1)
button2.pack() #加载到窗体
button2.place(x=1, y=1) #设置坐标(以程序界面大小为基准)
#进入消息循环机制
win.mainloop()
有不懂的可以在评论区提问!