Tkinter的基本用法
1:导入和新建
from tkinter import *
root = Tk()
root.mainloop()
2:设置标题和大小以及窗口位置
from tkinter import *
root = Tk()
root.title("TkinterSimple")
#窗口大小
width ,height= 600, 600
#窗口居中显示
root.geometry('%dx%d+%d+%d' % (width,height,(root.winfo_screenwidth() - width ) / 2, (root.winfo_screenheight() - height) / 2))
#窗口最大值
root.maxsize(600,600)
#窗口最小值
root.minsize(600,600)
root.mainloop()
3:常用的控件
from tkinter import *
root = Tk()
root.title("TkinterSimple")
width ,height= 600, 600
root.geometry('%dx%d+%d+%d' % (width,height,(root.winfo_screenwidth() - width ) / 2, (root.winfo_screenheight() - height) / 2))
root.maxsize(600,600)
root.minsize(600,600)
def prints():
print("button")
button = Button(root, text="Button", command=prints)
button.pack()
label = Label(root, text="Label")
label.pack()
entry = Entry(root)
entry.pack()
checkbutton = Checkbutton(root, text="CheckButton")
checkbutton.pack()
radioButton = Radiobutton(root, text="RadioButton")
radioButton.pack()
root.mainloop()