Python menu from list in Tkinter
tkinter popup menu
tkinter menu bar color
tkinter menu command arguments
Here I have a list which I am getting from the cursor of MYSQL connector. I have no problem in fetching the data. But I am interested in making a menu using the
OptionMenu feature of tkinter with the data I received. Here, is what I am trying
from tkinter import * r = Tk() name_ = StringVar() name = [('John',),('Jimmy',),('Smith',),('Rosel',)] #Here I am directly giving the list, but this the output which I get from cursor of MYSQL l= for i in range(len(name)-1): l.append(name[i]) print(l) t = tuple(l) name_.set('Select Student') option = OptionMenu(r,name_,l) option.pack()
But I don't think this helps as what I get is the whole list printed as a single option. Please help me.....
Please let me know if this is not what you want:
from tkinter import * from tkinter import ttk root = Tk() root.title("mysql") root.geometry("400x400") var = StringVar(root) var.set("select student") option = ttk.OptionMenu(root,var,'','John','Jimmy','Smith','Rosel') option["width"] = 20 option.pack() root.mainloop()
GUI Programming with Python: Menus in Tkinter, We introduce in this chapter of our Python Tkinter tutorial the pull-down menus of Tkinter, i.e. the lists at the top of the windows, which appear (or pull down),� Python - Tkinter Menu - The goal of this widget is to allow us to create all kinds of menus that can be used by our applications. The core functionality provides ways to create three m
You need to use python's
* operator to expand the list when calling
option = OptionMenu(r, name_, *l)
Python - Tkinter Menu, The goal of this widget is to allow us to create all kinds of menus that can be used by our applications. The core functionality provides ways to create three menu types: pop-up, toplevel and pull-down. A context menu is a menu in which the choices presented to the user are modified according to the current context in which the user is located. We introduce in this chapter of our Python Tkinter tutorial the pull-down menus of Tkinter, i.e. the lists at the top of the windows, which appear (or pull down), if you click on an item like, for
I hope it helps:
from tkinter import * from tkinter import ttk root = Tk() root.title("mysql") root.geometry(("400x400")) class Mysql: def __init__(self,parent): self.parent = parent self.options = [('John',),('Jimmy',),('Smith',),('Dave',)] self.var = StringVar(self.parent) self.var.set("Select Student") self.option = ttk.OptionMenu(self.parent,self.var,*self.options) self.option.pack() Mysql(root) root.mainloop()
Tk dropdown example - Python Tutorial, Tkinter supports dropdown menus. Python Desktop Apps with Tkinter The popup menu contains a list of options which is defined in the� Python Tkinter Menu . The Menu widget is used to create various types of menus (top level, pull down, and pop up) in the python application. The top-level menus are the one which is displayed just under the title bar of the parent window. We need to create a new instance of the Menu widget and add various commands to it by using the add() method.
Dropdown Menus With TKinter, In this video I'll show you how to create Dropdown menus with tKinter. Watch The Other Duration: 7:14 Posted: Apr 30, 2019 Menus in Tkinter (GUI Programming) The tkinter menu is a top-level pulldown menu. They are shown just under the title bar, as you’d expect from traditional gui apps. The menu can have multiple sub menus and each sub menu can contain items. Menu items can be associated with callback methods, meaning when you click them a Python method is called.
How to Create Dropdown Menu in Tkinter, This tutorial shows how to create drop down menu in Tkinter. pythonCopy import tkinter as tk OptionList = [ "Aries", "Taurus", "Gemini" OptionMenu couldn' t link a command when a new value is selected from the option list. It has some methods to create a dropdown menu in Tkinter. Use Combobox as introduced in the Tkinter tutorial Combobox chapter. Use OptionMenu Widget. The OptionMenu is similar to the Combobox widget but is already included in the Tkinter itself; therefore, you don’t need to import ttk module like in the case of Combobox.
Python, Python | Menu widget in Tkinter. Last Updated: 12-04-2019. Tkinter is Python's standard GUI (Graphical User Interface) package. It is one of the most commonly � Tkinter library has been used in the following code to create a GUI with a dropdown menu. Tkinter is Pythons defacto GUI library. It is not the only GUI toolkit in Python but is the most commonly used one. The library is packed with methods that can be used to create apps and a variety of GUIs with utmost ease and simplicity. Python program to
- Instantiate your OptionMenu like so
option = OptionMenu(r, name_, *l)to treat your list as multiple arguments.
- This won't work because they don't want to hard-code the menu, they want to populate it with data from a database.
- Why have you posted 2 answers? That said code only answers are not very useful. Please add a description of what you have done to fix the problem and why.
- Yes, this can also be done, but using a long defination obviously slows my program and I just want one menu, and I am a student and what I am trying is to make a student database management system as a part of my project work. So, using only
name_ ,*1is ok. Thanks.....