Tkinter的基本用法

来源:互联网 发布:java获取方法执行时间 编辑:程序博客网 时间:2024/05/21 10:07

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()

这里写图片描述

0 0