我试图创建一个简单的GUI,我使用了两个列表来捕获对下一步操作的选择。
我的真实列表“ mylist” 和“ mylist2” 有300多个元素, 300个超出屏幕限制的元素,当然; 我尝试实现滚动条来解决此问题,但我不知道该怎么做。
这是我的代码: 将tkinter导入为tk
import tkinter as tk
#start
root = tk.Tk()
root.geometry("550x550") #size
opt = [] #mylist
opt2 = [] #mylist2
def chkbox_checked():
for ix, item in enumerate(cb):
opt[ix]=(cb_v[ix].get())
print (opt)
mylist= [
'a'
,'b'
,'c'
,'d'
,'e']
mylist2= [
'1'
,'2'
,'3'
,'4'
,'5']
#list1
cb = []
cb_v = []
for ix, text in enumerate(mylist):
cb_v.append(tk.StringVar())
off_value=0 #whatever you want it to be when the checkbutton is off
cb.append(tk.Checkbutton(root, text=text, onvalue=text,offvalue=off_value,
variable=cb_v[ix],
command=chkbox_checked))
cb[ix].grid(row=ix, column=0, sticky='w')
opt.append(off_value)
cb[-1].deselect() #uncheck the boxes initially.
label = tk.Label(root, width=20)
label.grid(row=ix+1, column=0, sticky='w')
#list2
cb2 = []
cb_v2 = []
for ix, text in enumerate(mylist2):
cb_v2.append(tk.StringVar())
off_value=0 #whatever you want it to be when the checkbutton is off
cb2.append(tk.Checkbutton(root, text=text, onvalue=text,offvalue=off_value,
variable=cb_v2[ix],
command=chkbox_checked))
cb2[ix].grid(row=ix, column=9, sticky='w')
opt2.append(off_value)
cb2[-1].deselect() #uncheck the boxes initially.
label2 = tk.Label(root, width=20)
label2.grid(row=ix+1, column=9, sticky='w')
我如何实现一个存储“ mylist2” 的窗口和另一个存储“ mylist2” 和滚动条的窗口,以在复选框之间移动?
[预期]