optionmenu

Getting the choice of optionmenu right after selection Python

六眼飞鱼酱① 提交于 2020-01-10 17:06:19
问题 I was wondering if there is any way for me to see what the User has selected among the list displaying, let's say: ["Apple","Orange","Grapes"] right after they select either one of them? Like when user clicks the optionbox, and clicks Apple, Tkinter will return something then if he switches his selection to, let's say, Orange, then that will also return something on the spot. Thanks! How to put parameter correctly? from Tkinter import * def option_changed(a): print "the user chose the value {

Using Python with Tkinter, how can I make a button press do a different thing depending on which option is selected in the option menu?

岁酱吖の 提交于 2020-01-05 07:07:51
问题 I'm making a simple GUI, and my goal right now is for the user to select an option (kinematics or electricity) and then they would press the button to move on to a new screen for the one they selected. Currently, the button will do the same thing no matter which is selected, and I don't know how to change that. I'm using Python 3.6.1 from tkinter import * import tkinter.font bg_color1 = "#008B8B" abc = Tk() abc.title("Physics Problem Solver") abc.rowconfigure(0, weight=1) abc.columnconfigure

android change option menu text color

别等时光非礼了梦想. 提交于 2020-01-04 09:27:12
问题 I have been developing app these days, the code for changing text items: @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater=getMenuInflater(); inflater.inflate(R.menu.main, menu); int positionOfMenuItem = 0; // or whatever... MenuItem item = menu.getItem(positionOfMenuItem); SpannableString s = new SpannableString("My red MenuItem"); s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0); item.setTitleCondensed(s); return true; } it works pretty, but when

More on tkinter optionmenu first option vanishes

谁说我不能喝 提交于 2020-01-04 09:18:58
问题 This is a followup to my question here. I'm trying to use ttk.OptionMenu to enhance the look and feel of a dropdown menu. But as noted in the post here, "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..." The workaround as suggested in that post is to add an empty item to the list. In my case, since I am using a dictionary, adding '':[] as the first item in the dictionary fixed the

TKinter OptionMenu: How to get the selected choice?

孤街醉人 提交于 2020-01-01 05:10:30
问题 I am quite new at Python and Tkinter, but I have to create a simple form which requires the use of drop-down menus. I was trying to do something like this: #!/usr/bin python import sys from Tkinter import * # My frame for form class simpleform_ap(Tk): def __init__(self,parent): Tk.__init__(self,parent) self.parent = parent self.initialize() def initialize(self): self.grid() # Dropdown Menu optionList = ["Yes","No"] self.dropVar=StringVar() self.dropVar.set("Yes") # default choice self

Changing the selected item of an OptionMenu programmatically

我与影子孤独终老i 提交于 2019-12-25 16:58:34
问题 I have defined a simple OptionMenu like import Tkinter as tk optionList = ('a', 'b', 'c') v = tk.StringVar() v.set(optionList[0]) om = tk.OptionMenu(self, v, *optionList) This list will appear with a as default which is fine. But there are also command buttons defined which eventually need to alter this to show another of the available options (say b ). How can this be achieved? 回答1: You already found a way to set a default value and change it. You have the v variable associated to that

Tkinter - Only show filled values of an array in a OptionMenu

旧城冷巷雨未停 提交于 2019-12-25 03:59:23
问题 I've the following code: self.array_lt = ['foo', 'bar', '', 'moo'] var = StringVar() self.menult = OptionMenu(randomwindow, var, *self.array_lt) self.menult.config(width=30) self.menult.grid(row=0, column=0, padx=(5,5), pady=(5,5)) This shows me a OptionMenu with the four values, foo , bar , (the empty space) and moo . How can I show the OptionMenu without showing the empty value of the array? In another words, I want to show only foo , bar and moo on the OptionMenu and ignore the empty space

OptionMenu won't show the first option when clicked (Tkinter)

非 Y 不嫁゛ 提交于 2019-12-23 09:53:42
问题 I added a OptionMenu widget to my code, and assigned a list as it's options. This is how it is: z = StringVar() z.set(userList[0]) usersOption = OptionMenu(frame1, z, *userList)#, command=changeUser) usersOption.pack(side=RIGHT, padx=3) Now, I reckon it would show all the options in said list. As so: Option 1 \/ <-- the box with the selected option Option 1 }\__the options that show on click Option 2 }/ but it actually only shows the second option, and when I choose it there is, basically, no

How do populate a Tkinter optionMenu with items in a list

大城市里の小女人 提交于 2019-12-23 08:26:14
问题 "I want to populate option menus in Tkinter with items from various lists, how do i do that? In the code below it treats the entire list as one item in the menu. I tried to use a for statement to loop through the list but it only gave me the value 'a' several times. from Tkinter import * def print_it(event): print var.get() root = Tk() var = StringVar() var.set("a") lst = ["a,b,c,d,e,f"] OptionMenu(root, var, lst, command=print_it).pack() root.mainloop() I want to now pass the variable to

Python Tkinter: OptionMenu modify dropdown list width

不打扰是莪最后的温柔 提交于 2019-12-22 08:15:57
问题 I have created an OptionMenu from Tkinter with a columnspan of 2. However, the dropdown list/menu does not match the width, so it does not look good. Any idea on how to match their width? self.widgetVar = StringVar(self.top) choices = ['', 'wire', 'register'] typeOption = OptionMenu(self.top, self.widgetVar, *choices) typeOption.grid(column = 0, columnspan = 2, row = 0, sticky = 'NSWE', padx = 5, pady = 5) 回答1: There is no way to change the width of the dropdown. You might want to consider