为了账号安全,请及时绑定邮箱和手机立即绑定

python Tkinter库之OptionMenu控件问题?

python Tkinter库之OptionMenu控件问题?

三国纷争 2019-05-23 19:15:02
python Tkinter库之OptionMenu控件问题
查看完整描述

3 回答

?
HUWWW

TA贡献1874条经验 获得超12个赞

Tkinter居然没有这种组件,所以就只能模拟了

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

#! /usr/bin/python

# -*- coding: utf8 -*-

from Tkinter import *

class Select(Frame):

    def __init__(self,   master=None):

        Frame.__init__(self,   master)

        self.label = Label(self,   text="选择项目")

        self.listBox = Listbox(self,   height=1)

        self.button = Button(self,   text='V', command=self.triggle)

        self.hideList = True

        for i in xrange(10):

            self.listBox.insert(i, 'Item%d'%i)

        self.label.grid(row=0,   column=0, sticky=N)

        self.listBox.grid(row=0,   column=1, sticky=N)

        self.button.grid(row=0,   column=2, sticky=N)

        self.grid()

    def triggle(self):

        self.hideList   ^= 1

        self.listBox.config(height=[self.listBox.size(), 1][self.hideList])

app = Select()

app.mainloop()


查看完整回答
反对 回复 2019-05-25
  • 3 回答
  • 0 关注
  • 1368 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信