51Arduino32 发表于 2022-4-21 22:46:31

tkinter 的下拉框

求助,我想实现 Optionmenu下拉框的选项增加功能, 如图


下面是代码,望大佬解答如何实现
from glob import glob
from tkinter import *

window = Tk()
window.title("下拉菜单")
window.geometry("600x400")


options = # 默认选项
variable = StringVar()
variable.set(options)

count = 10
def addOptionMenu():
    global count
    count+=1
    print(count)
    options.append(count)
    window.update()

b = Button(window,text="添加",command=addOptionMenu)
b.pack()

omenu = OptionMenu(window,variable,*options)
omenu.pack()

window.mainloop()

amazed 发表于 2022-4-22 00:51:26

66666666666666

5584197 发表于 2022-4-22 01:15:31

不懂帮顶,希望问题早日解决

sls111 发表于 2022-4-22 09:07:36

好深奥 不会{:10_256:}{:10_256:}{:10_256:}

wiselin 发表于 2022-4-22 09:14:37

tkinter有combobox组件的啊,为啥要用optionmenu?

1050293757 发表于 2022-4-22 10:52:51

{:5_109:}

qq1151985918 发表于 2022-4-22 11:01:05

from glob import glob
from tkinter import *

window = Tk()
window.title("下拉菜单")
window.geometry("600x400")


options = # 默认选项
variable = StringVar()
variable.set(options)

count = 10
def addOptionMenu():
    global count
    count+=1
    print(count)
    options.append(count)
    omenu['menu'].add_command(label=count,command=lambda:None)
    window.update()

b = Button(window,text="添加",command=addOptionMenu)
b.pack()

omenu = OptionMenu(window,variable,*options)
omenu.pack()

window.mainloop()

fxj2002 发表于 2022-4-22 12:51:53

{:5_109:}

myqf123 发表于 2022-4-22 14:53:02

{:5_103:}

1molHF 发表于 2022-4-22 16:17:15

{:10_256:}

hornwong 发表于 2022-4-22 16:23:40

{:5_95:}

颖颖M杰杰 发表于 2022-4-24 16:22:50

{:5_108:}
页: [1]
查看完整版本: tkinter 的下拉框