tkinter optionmenu first option vanishes
A ttk optionmenu widget starts out with all of its values in the dropdown. Upon selecting any value, the first value in the list vanishes, never to reappear...
Does anyone know why? Is this a feature of the widget's design? Try it with the following:
import tkinter.ttk as ttk
import tkinter as tk
a = tk.Tk()
options = ['1', '2', '3']
value = tk.StringVar()
masterframe = ttk.Frame()
masterframe.pack()
dropdown = ttk.OptionMenu(masterframe, value, *options)
dropdown.pack()
a.mainloop()
Note - another user asked the same question here: OptionMenu won't show the first option when clicked (Tkinter)
They seem to've found a workaround, but not understood why it was happening.
UPDATE: actually this behaviour only appears when using the ttk widget. The tk widget works fine (albeit looking very ugly).
python tkinter ttk optionmenu
add a comment |
A ttk optionmenu widget starts out with all of its values in the dropdown. Upon selecting any value, the first value in the list vanishes, never to reappear...
Does anyone know why? Is this a feature of the widget's design? Try it with the following:
import tkinter.ttk as ttk
import tkinter as tk
a = tk.Tk()
options = ['1', '2', '3']
value = tk.StringVar()
masterframe = ttk.Frame()
masterframe.pack()
dropdown = ttk.OptionMenu(masterframe, value, *options)
dropdown.pack()
a.mainloop()
Note - another user asked the same question here: OptionMenu won't show the first option when clicked (Tkinter)
They seem to've found a workaround, but not understood why it was happening.
UPDATE: actually this behaviour only appears when using the ttk widget. The tk widget works fine (albeit looking very ugly).
python tkinter ttk optionmenu
add a comment |
A ttk optionmenu widget starts out with all of its values in the dropdown. Upon selecting any value, the first value in the list vanishes, never to reappear...
Does anyone know why? Is this a feature of the widget's design? Try it with the following:
import tkinter.ttk as ttk
import tkinter as tk
a = tk.Tk()
options = ['1', '2', '3']
value = tk.StringVar()
masterframe = ttk.Frame()
masterframe.pack()
dropdown = ttk.OptionMenu(masterframe, value, *options)
dropdown.pack()
a.mainloop()
Note - another user asked the same question here: OptionMenu won't show the first option when clicked (Tkinter)
They seem to've found a workaround, but not understood why it was happening.
UPDATE: actually this behaviour only appears when using the ttk widget. The tk widget works fine (albeit looking very ugly).
python tkinter ttk optionmenu
A ttk optionmenu widget starts out with all of its values in the dropdown. Upon selecting any value, the first value in the list vanishes, never to reappear...
Does anyone know why? Is this a feature of the widget's design? Try it with the following:
import tkinter.ttk as ttk
import tkinter as tk
a = tk.Tk()
options = ['1', '2', '3']
value = tk.StringVar()
masterframe = ttk.Frame()
masterframe.pack()
dropdown = ttk.OptionMenu(masterframe, value, *options)
dropdown.pack()
a.mainloop()
Note - another user asked the same question here: OptionMenu won't show the first option when clicked (Tkinter)
They seem to've found a workaround, but not understood why it was happening.
UPDATE: actually this behaviour only appears when using the ttk widget. The tk widget works fine (albeit looking very ugly).
python tkinter ttk optionmenu
python tkinter ttk optionmenu
edited Mar 11 '18 at 20:22


Mr. T
4,18791535
4,18791535
asked Oct 2 '13 at 13:50
TomTom
126315
126315
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The signature of the ttk.OptionMenu command is this:
def __init__(self, master, variable, default=None, *values, **kwargs):
This is the docstring:
"""Construct a themed OptionMenu widget with master as the parent, the
resource textvariable set to variable, the initially selected value
specified by the default parameter, the menu values given by
*values and additional keywords.
Notice the default
option which comes before the list of values. Instead of adding a blank item to the list of values, add whichever value you want as the default:
options = ['1', '2', '3']
dropdown = ttk.OptionMenu(masterframe, value, options[1], *options)
5
haha, great, you added a good answer to a 1-year old question exactly 4 hours before I needed that.
– Gregor
Aug 9 '14 at 15:24
add a comment |
It seems that with ttk.OptionMenu
the first entry in the options list must be left blank:
import tkinter.ttk as ttk
import tkinter as tk
a = tk.Tk()
options = ['', '1', '2', '3']
value = tk.StringVar()
value.set(options[1])
masterframe = ttk.Frame()
masterframe.pack()
dropdown = ttk.OptionMenu(masterframe, value, *options)
dropdown.pack()
a.mainloop()
Source: http://www.pyinmyeye.com/2012/08/tkinter-menubutton-demo.html
That link appears to be dead.
– Bryan Oakley
Aug 9 '14 at 11:03
3
While your workaround works, it's not a very good description of the problem.ttk.OptionMenu
expects a default value after the variable argument and before the list of values. While your solution works, it obscurs what is really happening.
– Bryan Oakley
Aug 9 '14 at 11:19
Hahaha, I like this a lot!!
– StackG
Jun 17 '18 at 11:05
add a comment |
just adding to the answers of the other guys, since they didn't work for me. I discovered that if you don't set the widget option in StringVar/IntVar, it doesn't show the standard value that's been set. It might seem silly but it took me a lot of time to figure this out. Hope it helps, see ya.
Example:
master = tk.Tk()
var = tk.StringVar(master)
master.mainloop()
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19138534%2ftkinter-optionmenu-first-option-vanishes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The signature of the ttk.OptionMenu command is this:
def __init__(self, master, variable, default=None, *values, **kwargs):
This is the docstring:
"""Construct a themed OptionMenu widget with master as the parent, the
resource textvariable set to variable, the initially selected value
specified by the default parameter, the menu values given by
*values and additional keywords.
Notice the default
option which comes before the list of values. Instead of adding a blank item to the list of values, add whichever value you want as the default:
options = ['1', '2', '3']
dropdown = ttk.OptionMenu(masterframe, value, options[1], *options)
5
haha, great, you added a good answer to a 1-year old question exactly 4 hours before I needed that.
– Gregor
Aug 9 '14 at 15:24
add a comment |
The signature of the ttk.OptionMenu command is this:
def __init__(self, master, variable, default=None, *values, **kwargs):
This is the docstring:
"""Construct a themed OptionMenu widget with master as the parent, the
resource textvariable set to variable, the initially selected value
specified by the default parameter, the menu values given by
*values and additional keywords.
Notice the default
option which comes before the list of values. Instead of adding a blank item to the list of values, add whichever value you want as the default:
options = ['1', '2', '3']
dropdown = ttk.OptionMenu(masterframe, value, options[1], *options)
5
haha, great, you added a good answer to a 1-year old question exactly 4 hours before I needed that.
– Gregor
Aug 9 '14 at 15:24
add a comment |
The signature of the ttk.OptionMenu command is this:
def __init__(self, master, variable, default=None, *values, **kwargs):
This is the docstring:
"""Construct a themed OptionMenu widget with master as the parent, the
resource textvariable set to variable, the initially selected value
specified by the default parameter, the menu values given by
*values and additional keywords.
Notice the default
option which comes before the list of values. Instead of adding a blank item to the list of values, add whichever value you want as the default:
options = ['1', '2', '3']
dropdown = ttk.OptionMenu(masterframe, value, options[1], *options)
The signature of the ttk.OptionMenu command is this:
def __init__(self, master, variable, default=None, *values, **kwargs):
This is the docstring:
"""Construct a themed OptionMenu widget with master as the parent, the
resource textvariable set to variable, the initially selected value
specified by the default parameter, the menu values given by
*values and additional keywords.
Notice the default
option which comes before the list of values. Instead of adding a blank item to the list of values, add whichever value you want as the default:
options = ['1', '2', '3']
dropdown = ttk.OptionMenu(masterframe, value, options[1], *options)
edited Dec 17 '14 at 21:57
answered Aug 9 '14 at 11:18
Bryan OakleyBryan Oakley
216k22258421
216k22258421
5
haha, great, you added a good answer to a 1-year old question exactly 4 hours before I needed that.
– Gregor
Aug 9 '14 at 15:24
add a comment |
5
haha, great, you added a good answer to a 1-year old question exactly 4 hours before I needed that.
– Gregor
Aug 9 '14 at 15:24
5
5
haha, great, you added a good answer to a 1-year old question exactly 4 hours before I needed that.
– Gregor
Aug 9 '14 at 15:24
haha, great, you added a good answer to a 1-year old question exactly 4 hours before I needed that.
– Gregor
Aug 9 '14 at 15:24
add a comment |
It seems that with ttk.OptionMenu
the first entry in the options list must be left blank:
import tkinter.ttk as ttk
import tkinter as tk
a = tk.Tk()
options = ['', '1', '2', '3']
value = tk.StringVar()
value.set(options[1])
masterframe = ttk.Frame()
masterframe.pack()
dropdown = ttk.OptionMenu(masterframe, value, *options)
dropdown.pack()
a.mainloop()
Source: http://www.pyinmyeye.com/2012/08/tkinter-menubutton-demo.html
That link appears to be dead.
– Bryan Oakley
Aug 9 '14 at 11:03
3
While your workaround works, it's not a very good description of the problem.ttk.OptionMenu
expects a default value after the variable argument and before the list of values. While your solution works, it obscurs what is really happening.
– Bryan Oakley
Aug 9 '14 at 11:19
Hahaha, I like this a lot!!
– StackG
Jun 17 '18 at 11:05
add a comment |
It seems that with ttk.OptionMenu
the first entry in the options list must be left blank:
import tkinter.ttk as ttk
import tkinter as tk
a = tk.Tk()
options = ['', '1', '2', '3']
value = tk.StringVar()
value.set(options[1])
masterframe = ttk.Frame()
masterframe.pack()
dropdown = ttk.OptionMenu(masterframe, value, *options)
dropdown.pack()
a.mainloop()
Source: http://www.pyinmyeye.com/2012/08/tkinter-menubutton-demo.html
That link appears to be dead.
– Bryan Oakley
Aug 9 '14 at 11:03
3
While your workaround works, it's not a very good description of the problem.ttk.OptionMenu
expects a default value after the variable argument and before the list of values. While your solution works, it obscurs what is really happening.
– Bryan Oakley
Aug 9 '14 at 11:19
Hahaha, I like this a lot!!
– StackG
Jun 17 '18 at 11:05
add a comment |
It seems that with ttk.OptionMenu
the first entry in the options list must be left blank:
import tkinter.ttk as ttk
import tkinter as tk
a = tk.Tk()
options = ['', '1', '2', '3']
value = tk.StringVar()
value.set(options[1])
masterframe = ttk.Frame()
masterframe.pack()
dropdown = ttk.OptionMenu(masterframe, value, *options)
dropdown.pack()
a.mainloop()
Source: http://www.pyinmyeye.com/2012/08/tkinter-menubutton-demo.html
It seems that with ttk.OptionMenu
the first entry in the options list must be left blank:
import tkinter.ttk as ttk
import tkinter as tk
a = tk.Tk()
options = ['', '1', '2', '3']
value = tk.StringVar()
value.set(options[1])
masterframe = ttk.Frame()
masterframe.pack()
dropdown = ttk.OptionMenu(masterframe, value, *options)
dropdown.pack()
a.mainloop()
Source: http://www.pyinmyeye.com/2012/08/tkinter-menubutton-demo.html
answered Oct 7 '13 at 18:18
J. NunesJ. Nunes
271
271
That link appears to be dead.
– Bryan Oakley
Aug 9 '14 at 11:03
3
While your workaround works, it's not a very good description of the problem.ttk.OptionMenu
expects a default value after the variable argument and before the list of values. While your solution works, it obscurs what is really happening.
– Bryan Oakley
Aug 9 '14 at 11:19
Hahaha, I like this a lot!!
– StackG
Jun 17 '18 at 11:05
add a comment |
That link appears to be dead.
– Bryan Oakley
Aug 9 '14 at 11:03
3
While your workaround works, it's not a very good description of the problem.ttk.OptionMenu
expects a default value after the variable argument and before the list of values. While your solution works, it obscurs what is really happening.
– Bryan Oakley
Aug 9 '14 at 11:19
Hahaha, I like this a lot!!
– StackG
Jun 17 '18 at 11:05
That link appears to be dead.
– Bryan Oakley
Aug 9 '14 at 11:03
That link appears to be dead.
– Bryan Oakley
Aug 9 '14 at 11:03
3
3
While your workaround works, it's not a very good description of the problem.
ttk.OptionMenu
expects a default value after the variable argument and before the list of values. While your solution works, it obscurs what is really happening.– Bryan Oakley
Aug 9 '14 at 11:19
While your workaround works, it's not a very good description of the problem.
ttk.OptionMenu
expects a default value after the variable argument and before the list of values. While your solution works, it obscurs what is really happening.– Bryan Oakley
Aug 9 '14 at 11:19
Hahaha, I like this a lot!!
– StackG
Jun 17 '18 at 11:05
Hahaha, I like this a lot!!
– StackG
Jun 17 '18 at 11:05
add a comment |
just adding to the answers of the other guys, since they didn't work for me. I discovered that if you don't set the widget option in StringVar/IntVar, it doesn't show the standard value that's been set. It might seem silly but it took me a lot of time to figure this out. Hope it helps, see ya.
Example:
master = tk.Tk()
var = tk.StringVar(master)
master.mainloop()
add a comment |
just adding to the answers of the other guys, since they didn't work for me. I discovered that if you don't set the widget option in StringVar/IntVar, it doesn't show the standard value that's been set. It might seem silly but it took me a lot of time to figure this out. Hope it helps, see ya.
Example:
master = tk.Tk()
var = tk.StringVar(master)
master.mainloop()
add a comment |
just adding to the answers of the other guys, since they didn't work for me. I discovered that if you don't set the widget option in StringVar/IntVar, it doesn't show the standard value that's been set. It might seem silly but it took me a lot of time to figure this out. Hope it helps, see ya.
Example:
master = tk.Tk()
var = tk.StringVar(master)
master.mainloop()
just adding to the answers of the other guys, since they didn't work for me. I discovered that if you don't set the widget option in StringVar/IntVar, it doesn't show the standard value that's been set. It might seem silly but it took me a lot of time to figure this out. Hope it helps, see ya.
Example:
master = tk.Tk()
var = tk.StringVar(master)
master.mainloop()
edited Nov 21 '18 at 2:39


Marcus Campbell
2,01921127
2,01921127
answered Nov 21 '18 at 1:18


Pedro MorescoPedro Moresco
214
214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19138534%2ftkinter-optionmenu-first-option-vanishes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown