一、创建单选框
1 form tkinter import * 2 #创建窗口体 3 window = tk() 4 #初始化组合件绑定 5 w1 = IntVar() 6 #设置初始选择项1 7 w1.set(1) 8 def Occupation(): 9 lable = Label(text="请选择职业").place(x=20,y=15) 10 m=1 11 for i in occupation_list: 12 #创建单选框,绑定到window窗口,组合件绑定,设置单选内容,设置初始化选项值 13 a = Radiobutton(window, variable=w1, text=i, value=m,).place(x=20, y=20+m*20) 14 m = m+1
**通过单选框的位置得到value的值(第几号),并通过第几号得到相应的内容及text的值
zhi1 = w1.get()
zhi2 = occupation_list [ zhi1 - 1]
二、创建数据表格视图(Treeview)
1 form tkinter import ttk 2 window = Tk() 3 def SjTreeview(): 4 #创建数据窗体绑定到window中,show="headings" 首列隐藏,并设立2个标签,高度15 5 tree = ttk.Treeview(window,show="headings",columns=("职业","种族"),height=15) 6 #设立每各标签宽度,居中对齐 7 tree.column("职业",width=50,anchor=‘center‘) 8 tree.column("种族",width=50,anchor=‘center‘) 9 #设立每个标签的头 10 tree.heading("职业",text="职业") 11 tree.heading("种族",text="种族") 12 tree.place(x=200,y=20)
三、创建按钮
1 def Tbutton(): 2 #绑定窗口,设置按钮的名字,设置按钮的命令 3 button = Button(window,text="添加",command=tianjia).place(x=300,y=300) 4 button = Button(window,text="删除",command=del_func).place(x=350, y=300) 5 button = Button(window,text="清空",command=clear_treeview).place(x=400, y=300)
四、窗口的自循环启动
1 def Tbutton(): 2 #绑定窗口,设置按钮的名字,设置按钮的命令 3 button = Button(window,text="添加",command=tianjia).place(x=300,y=300) 4 button = Button(window,text="删除",command=del_func).place(x=350, y=300) 5 button = Button(window,text="清空",command=clear_treeview).place(x=400, y=300)
更多精彩文章关注公众号python社区营