初识tkinter
程序员文章站
2022-04-12 11:42:24
...
import tkinter
win=tkinter.Tk()#创建窗口
win.title(string="古诗鉴赏")#窗口标题
b=tkinter.Label(win,text="花间一壶酒,独酌无相亲。举杯邀明月,对影成三人。")#标签控件
b.pack()#设置窗口大小,位置
win.mainloop()
grid()控件位置
from tkinter import *
win=Tk()
frame=Frame(win,relief=RAISED,borderwidth=2)
frame.pack(side=TOP,fill=BOTH,ipadx=5,ipady=5,expand=1)
for i in range(5):
for j in range(5):
Button(frame,text="("+str(i)+","+str(j)+")").grid(row=i,column=j)
win.mainloop()
place()控件位置
from tkinter import *
#主窗口
win=Tk()
#创建窗体
frame=Frame(win,relief=RAISED,borderwidth=2,width=400,height=400)
frame.pack(side=TOP,fill=BOTH,ipadx=5,ipady=5,expand=1)
#第一个按钮在(40,40)
button1=Button(frame,text="Button1")
button1.place(x=40,y=40,anchor=W,width=80,height=40)
#第2个按钮在(140,80)
button1=Button(frame,text="Button2")
button1.place(x=140,y=80,anchor=W,width=80,height=40)
win.mainloop()