在上面的示例中,首先导入了Tkinter库,并创建了一个名为center_window的函数,用于将窗口居中显示。然后创建了一个窗口对象window和一个按钮对象button,并指定了按钮的文本和点击事件处理函数。接下来,使用pack方法将按钮添加到窗口中,并调用center_window函数将窗口居中显示。最后,调用mainloop方法
Python打包工具PyInstaller使用-F参数生成单一exe文件,tkinter创建GUI应用,包含多种控件如Button、Label等,支持布局管理pack/grid/place,事件处理及对话框应用。
from tkinter import Tk from tkinter.ttk import Label, Button from PIL import Image, ImageTk global image class demo: def __init__(self, win): self.root = win self.gui_init() def gui_init(self): show_image = Label(self.root, relief="solid") show_but = Button(self.root, text="...
button1=tkinter.Button(root,anchor=tkinter.E,text="按钮1",width=30,height=7) button1.pack() button2=tkinter.Button(root,text="按钮2",bg='blue') button2.pack() button3=tkinter.Button(root,text="button3",width=12,height=1) button3.pack() button4=tkinter.Button(root,text="button4",...
Anchor 表示在parcel放置组件的方式,缺省时CENTER。 2 grid 使 用方法和pack类似。 3 place 精 确的摆放一个组件的位置,一般不太用。 关 于这个三个的详细使用和算法可以参考相关资料。 下 面看最后一个例子: 1 2 3 4 5 6 7 8 9 10 11
pack() ch4 = Checkbutton(root,text='田径',variable = CheckVar4,onvalue=1,offvalue=0) ch4.pack() btn1 = Button(root,text="OK",command=run) btn1.pack() btn2 = Button(root,text="全选",command=selectall) btn2.pack() btn3 = Button(root,text="清除",command=clear) btn3.pack() ...
on_hit=False varText.set("")# 定义buttonb= tk.Button(window,text='hit me',width=10,height=2,command=hit_me) b.pack() window.mainloop() Label的相关属性: anchor:文本或图像在背景内容区的位置,默认为 center,可选值为(n,s,w,e,ne,nw,sw,se,center)eswn 是东南西北英文的首字母,表示:上...
def say_hello():label.config(text="Hello World!")#创建一个顶级窗口(root window),这是整个GUI程序的基础。root = tk.Tk()#创建一个标签(Label),设置其初始文本为"Click the button to say hello!",并将其添加到根窗口中。label = tk.Label(root, text="Click the button to say hello!")label....
(window, text='选择你最喜欢的国家', bg='yellow', fg='blue', width=100) label.pack() for k, country in countrys.items(): radio_country = tk.Radiobutton(window, text=country, variable=var, width=100, indicatoron=0, value=k, command=print_country) radio_country.pack(anchor='center'...
2. 如果该选项设置为 “center”,文本显示在图像上(文本重叠图像) 3. 设置为 “bottom”,“left”,“right” 或“top”,那么图像显示在文本的旁边,比如如"bottom",则显示图像在文本的下方。disabledforeground指定当 Radiobutton 不可用的时的前景色颜色,默认由系统指定indicatoron1. 该参数表示选项前面的小圆圈是...