Tkinter下拉列表复选框/组合框 [英] Tkinter drop down list of check-boxes/combo-boxes

查看:213
本文介绍了Tkinter下拉列表复选框/组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Python创建一个后处理数据应用程序,并且正在使用Tkinter为此设计GUI。

I am attempting to create a post-processing data application in Python, and I am designing the GUI for this using Tkinter.

我不知道Tkinter是否支持包含复选框的下拉列表,然后可以从中选择多个复选框。下面的图片反映了我要描述的内容:

I do not know if Tkinter supports a drop down list composed of check boxes, of which you can then select multiple boxes from. The picture below reflects what I am attempting to describe:

这可能吗?

推荐答案

from Tkinter import *

top = Tk()

mb=  Menubutton ( top, text="CheckComboBox", relief=RAISED )
mb.grid()
mb.menu  =  Menu ( mb, tearoff = 0 )
mb["menu"]  =  mb.menu

Item0 = IntVar()
Item1 = IntVar()
Item2 = IntVar()

mb.menu.add_checkbutton ( label="Item0", variable=Item0)
mb.menu.add_checkbutton ( label="Item1", variable=Item1)
mb.menu.add_checkbutton ( label="Item2", variable=Item2)


'''This part is only for testing
def Item_test():
    if Item0.get() == True:
        print "Item0 True"
    elif Item0.get() == False:
        print "Item0 False"
    else:
        print Item0.get()
    if Item1.get() == True:
        print "Item1 True"
    elif Item1.get() == False:
        print "Item1 False"
    else:
        print Item1.get()
    if Item2.get() == True:
        print "Item2 True"
    elif Item2.get() == False:
        print "Item2 False"
    else:
        print Item2.get()

button1 = Button(top, text="Item True/False Test", command = Item_test)
button1.pack()
''' 

mb.pack()
top.mainloop()

这篇关于Tkinter下拉列表复选框/组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆