python界面问题,如何在一个listbox或grid中插入动态radio或checkbox?
python界面问题,如何在一个listbox或grid中动态插入radio或checkbox?
有一个文件需要逐行提取数据,并显示结果,并逐行动态插入radio或checkbox,以方便手动操作处理;
回答:
一个简易的demo,按下Add或Remove按钮,会动态地增减Checkbutton。
不管用什么UI,思路都是一样的,需要增加的时候新建一个对象,初始化,然后pick显示或隐藏pack_forget,Qt里面对应的是show,hide,或者__del__
#!/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()
以上是 python界面问题,如何在一个listbox或grid中插入动态radio或checkbox? 的全部内容, 来源链接: utcz.com/p/937778.html