3 回答
![?](http://img1.sycdn.imooc.com/545863e80001889e02200220-100-100.jpg)
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() |
添加回答
举报