python tk下拉列表_Python TKinter下拉菜单问题

fromtkinterimport*ALL=N+S+W+E

users=['Fred Asus','Tom Yahoo','Jessy Samsung','Jermain Sony','Nikki Nikon','Ian IBM','Elena Google','Rob Braun','Tammy Tonika','James Intel','Murphy Richards','Daniel Denon']branchlst={138:'Driving - St Albans',170:'Brighton',271:'Driving - Birmingham',330:'Leeds',680:'Edinburgh'}classApplication(Frame):def__init__(self,master=None):#initiate the primary window.Frame.__init__(self,master)self.master.rowconfigure(0,weight=1)self.master.columnconfigure(0,weight=1)self.rowconfigure(0,weight=0)self.rowconfigure(1,weight=0)self.rowconfigure(2,weight=3)self.columnconfigure(0,weight=0)self.columnconfigure(1,weight=1)self.columnconfigure(2,weight=1)self.grid(sticky=ALL)self.frameset()defframeset(self):#define and setup frames with columns and rows for widgets#Colours added to framesets to help designing layout. delete themself.Frame1=Frame(self)# Dself.Frame2=Frame(self,bg='blue')# Eself.Frame3=Frame(self)# Lself.Frame4=Frame(self,bg='blue')# Eself.Frame5=Frame(self)# Tself.Frame6=Frame(self)# E coloursself.Frame1.rowconfigure(0,weight=0)self.Frame2.rowconfigure(0,weight=0)self.Frame3.rowconfigure(0,weight=1)self.Frame4.rowconfigure(0,weight=1)self.Frame5.rowconfigure(0,weight=1)self.Frame6.rowconfigure(0,weight=1)self.Frame1.columnconfigure(0,weight=0)self.Frame2.columnconfigure(0,weight=0)self.Frame3.columnconfigure(0,weight=1)self.Frame4.columnconfigure(0,weight=1)self.Frame5.columnconfigure(0,weight=1)self.Frame6.columnconfigure(0,weight=1)self.Frame1.grid(row=0,column=0,rowspan=1,columnspan=1,sticky=ALL)self.Frame2.grid(row=0,column=1,columnspan=2,sticky=ALL)self.Frame3.grid(row=1,column=0,rowspan=2,sticky=ALL)self.Frame4.grid(row=1,column=1,columnspan=2,sticky=ALL)self.Frame5.grid(row=2,column=1,rowspan=1,columnspan=1,sticky=ALL)self.Frame6.grid(row=2,column=2,sticky=ALL)label4a=Label(self.Frame4,text='table1',bg='orange')label4b=Label(self.Frame4,text='table2',bg='yellow')label4a.pack(side=LEFT)label4b.pack(side=RIGHT)self.objects()defobjects(self):var=StringVar()var.set('Name')self.dmenu1=OptionMenu(self.Frame1,var,'Costcode','Name')self.dmenu1.pack(side=TOP,fill=BOTH)self.dmenu1.bind("",self.branches)self.f3ListBox=Listbox(self.Frame3,selectmode='single')#self.branches()self.f3ListBox.grid(sticky=ALL)self.f3ListBox.bind("",self.f1handler1)f5ListBox=Listbox(self.Frame5,selectmode='single')n=0foriteminusers:f5ListBox.insert(n,item)n+=1f5ListBox.grid(sticky=ALL)f6ListBox=Listbox(self.Frame6,selectmode='single')f6ListBox.insert(1,'S123456')# DELETEf6ListBox.insert(2,'S313414')# DELETEf6ListBox.insert(3,'S573343')# DELETEf6ListBox.grid(sticky=ALL)deff1handler1(self,event):"""Creates a popup menu for the alternative mouse button.

Edit this to add more options to that popup"""select=lambda:self.f3ListBox.delete(ACTIVE)popup=Menu(self,tearoff=0)popup.add_command(label='Quit',command=self.quit)popup.add_command(label='delete',command=select)#add more of these for more optionstry:popup.post(event.x_root,event.y_root)except:passdefbranches(self,event):self.f3ListBox.delete(0,END)n=0ifself.dmenu1.cget('text')=='Costcode':cc=sorted(list(branchlst.keys()))foritemincc:self.f3ListBox.insert(n,str(item)+' '+branchlst[item])n+=1elifself.dmenu1.cget('text')=='Name':bb=sorted(list(branchlst.values()))foriteminbb:forname,valinbranchlst.items():ifitem==val:self.f3ListBox.insert(n,item+' '+str(name))root=Tk()app=Application(master=root)app.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值