| 
 | 
 
5鱼币 
Tkinter中的gird()如何让不同控件不贴在一起 
 
为了方便观察控件的位置,各控件的sticky属性设置为了N + S + W + E 
 
各个控件的设置的行和列已在图中标注 
 
 
- from tkinter import *
 
  
- root = Tk()
 
 - root.geometry('1000x500')
 
  
- theButton1 = Button(root, text='导入名单')
 
 - theButton1.grid(row=0, column=0,  sticky=N + S + W + E)  # 导入名单按钮
 
  
- # 创建一个空列表
 
 - theLB = Listbox(root)
 
 - theLB.grid(row=0, column=3)
 
  
- #点名状态组
 
 - group = LabelFrame(root, text='状态', padx=5, pady=5)
 
 - group.grid(row=0, column=4, sticky=N + S + W + E)
 
 - KIND = [('出勤', 1), ('请假', 2), ('旷课', 3)]
 
 - v = IntVar()
 
 - for kind, num in KIND:
 
 -     b = Radiobutton(group, text=kind, variable=v, value=num)
 
 -     b.pack(anchor=W)
 
  
 
- theButton = Button(root, text="输出状态",)
 
 - theButton.grid(row=1, column=4, sticky=N + S + W + E)
 
  
- theButton = Button(root, text="删除", command=lambda x=theLB: x.delete(ACTIVE))
 
 - theButton.grid(row=1, column=3, sticky=N + S + W + E)
 
  
 
- mainloop()  # 导入根窗口
 
  复制代码 |   
 
 
 
 
 
 |