鱼C论坛

 找回密码
 立即注册
查看: 2615|回复: 3

Tkinter中的gird()如何让不同控件不贴在一起

[复制链接]
发表于 2021-9-29 17:30:22 | 显示全部楼层 |阅读模式
5鱼币
Tkinter中的gird()如何让不同控件不贴在一起

为了方便观察控件的位置,各控件的sticky属性设置为了N + S + W + E

各个控件的设置的行和列已在图中标注
搜狗截图20210929172431.png
  1. from tkinter import *

  2. root = Tk()
  3. root.geometry('1000x500')

  4. theButton1 = Button(root, text='导入名单')
  5. theButton1.grid(row=0, column=0,  sticky=N + S + W + E)  # 导入名单按钮

  6. # 创建一个空列表
  7. theLB = Listbox(root)
  8. theLB.grid(row=0, column=3)

  9. #点名状态组
  10. group = LabelFrame(root, text='状态', padx=5, pady=5)
  11. group.grid(row=0, column=4, sticky=N + S + W + E)
  12. KIND = [('出勤', 1), ('请假', 2), ('旷课', 3)]
  13. v = IntVar()
  14. for kind, num in KIND:
  15.     b = Radiobutton(group, text=kind, variable=v, value=num)
  16.     b.pack(anchor=W)


  17. theButton = Button(root, text="输出状态",)
  18. theButton.grid(row=1, column=4, sticky=N + S + W + E)

  19. theButton = Button(root, text="删除", command=lambda x=theLB: x.delete(ACTIVE))
  20. theButton.grid(row=1, column=3, sticky=N + S + W + E)


  21. mainloop()  # 导入根窗口
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-9-30 17:13:50 | 显示全部楼层
你想做成什么样?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-9-30 18:42:55 | 显示全部楼层
已经解决了 对width,columnspan,rowspan参数进行设置,就可以使不同控件不贴在一起
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-9-30 18:46:32 | 显示全部楼层

搜狗截图20210930184457.png
这样子的,我后来设置了控件的width以及gird的columnspan和rowspan,控件就不贴在一起了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-3 09:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表