from Tkinter import *

master = Tk()

def ChangeOpt1():
    Options.option_clear()
    Options.option_add("Apple","Orange","Melon")
    Options.update()
def ChangeOpt2():
    Options.option_clear()
    Options.option_add("Milk","Water","Juice")
    Options.update()
Option1=Checkbutton(text="OPTION1",indicatoron=0,command=ChangeOpt1)
Option1.pack()
Option2=Checkbutton(text="OPTION2",indicatoron=0,command=ChangeOpt2)
Option2.pack()


variable = StringVar(master)
variable.set("You have to check an option")
Options= OptionMenu(master, variable, "You have to check an option")
Options.pack()

mainloop()

I want to do that when I clicked Option1, Options be cleaned and it has to add "Apple",etc.. When I clicked Options be cleaned and add "Milk" etc..

Thank you for help.

Hello. I waited for 3 days.... anyone???

Thanks for answer. So I understood that Tkinter cant use combobox.

Thanks for answer. So I understood that Tkinter cant use combobox.

When you work with Tkinter, don't hesitate to use Pmw. It's only a small appendix to Tkinter, but very useful. A bible for Tkinter programming is the book by John Grayson (Python and Tkinter programming): he uses Pmw all the time.

Here is a typical example that might work for you:

# using Tkinter's Optionmenu() as a combobox
# allows one item to be selected
# use trace() and globalgetvar(name) to show selected choice

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def show_choice(name, index, mode):
    sf = "value is %s" % root.globalgetvar(name)
    root.title(sf)


root = tk.Tk()

choices = ['red', 'green', 'blue', 'yellow','white']
color = tk.StringVar(root)
color.trace('w', show_choice)
# optionally preselect a choice
color.set(choices[2])
color_option = tk.OptionMenu(root, color, *choices)
color_option.pack(padx=70, pady=10)

root.mainloop()
from Tkinter import *
from  Tkinter import  _setit

master = Tk()
variable = StringVar(master)
var=("1","2","3")
var1=("Apple","Orange","Melon")
def ChangeOpt1():
    Options["menu"].delete(0,"end")
    for item in var1:
        Options['menu'].add_command(label=item,
                    command=_setit(variable,item))
        variable.set(item)
def ChangeOpt2():
    Options["menu"].delete(0,"end")
    for item in var:
        Options['menu'].add_command(label=item,
                    command=_setit(variable,item))
        variable.set(item)
Opt=IntVar()
Option1=Radiobutton(text="OPTION1",indicatoron=0,variable=Opt,value=1,command=ChangeOpt1)
Option1.pack()
Option2=Radiobutton(text="OPTION2",indicatoron=0,variable=Opt,value=2,command=ChangeOpt2)
Option2.pack()


variable = StringVar(master)
variable.set("You have to check an option")
Options= OptionMenu(master, variable, "You have to check an option")
Options.pack()

mainloop()

I solved it. İf someone needs it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.