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