python界面问题,如何在一个listbox或grid中插入动态radio或checkbox?

python界面问题,如何在一个listbox或grid中动态插入radio或checkbox?
有一个文件需要逐行提取数据,并显示结果,并逐行动态插入radio或checkbox,以方便手动操作处理;image.pngimage.pngimage.png

阅读 2k
1 个回答

一个简易的demo,按下Add或Remove按钮,会动态地增减Checkbutton。
不管用什么UI,思路都是一样的,需要增加的时候新建一个对象,初始化,然后pick显示或隐藏pack_forget,Qt里面对应的是show,hide,或者__del__
Screenshot from 2020-03-12 09-35-24.png
Screenshot from 2020-03-12 09-35-42.png

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
from tkinter import *
import tkinter
 
top = tkinter.Tk()
CheckVar1 = IntVar()
CheckVar2 = IntVar()
C1 = Checkbutton(top, text = "RUNOOB", variable = CheckVar1, \
                 onvalue = 1, offvalue = 0, height=5, \
                 width = 20)
C2 = Checkbutton(top, text = "GOOGLE", variable = CheckVar2, \
                 onvalue = 1, offvalue = 0, height=5, \
                 width = 20)
C1.pack()
C2.pack()

Checkbutton_list = []
def add():
    CheckVar = IntVar()
    C = Checkbutton(top, text = "33333", variable = CheckVar, \
                 onvalue = 1, offvalue = 0, height=5, \
                 width = 20)
    C.pack()
    Checkbutton_list.append((C,CheckVar))

def remove():
    if len(Checkbutton_list):
        Checkbutton_list[0][0].pack_forget()
        del Checkbutton_list[0]

B1 = tkinter.Button(top, text ="Add", command = add)
B2 = tkinter.Button(top, text ="Remove", command = remove)
B1.pack()
B2.pack()

top.mainloop()
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏