Is it possible take user text input in a Tkinter dropdown menu? If so, how?

Regulation Headgear

This is what I have tried:

win = Tk()
menubar = Menu(win)
dropDown = Menu(menubar)
dropDown.add_command(label = "Do something", command = ...)

entry = Entry()
dropDown.add(entry)

menubar.add_cascade(label = "Drop Down", menu = dropDown)
win.config(menu = menubar)
win.update()

I have looked through the docs and it seems like there is no way to do it with a single line like dropDown.add_entry(...), but I thought there might be a workaround like using the one of the geometry manager to place the entry in the menu somehow.

I am using Python 3.6 (but I'm not tagging it because I'll get a thousand mods from the Python tag who have no interest in answering my question voting to close for no reason)

Mike - SMT

Here is a simple program where you can click a menu button to prompt the user for input. Then do something with that input. In this case print to console.

We need to write a function that makes use of askstring() from simpledialog that you can import from Tkinter. Then take the results of that string the user types and do something with it.

import tkinter as tk
from tkinter import simpledialog


win = tk.Tk()
win.geometry("100x50")

def take_user_input_for_something():
    user_input = simpledialog.askstring("Pop up for user input!", "What do you want to ask the user to input here?")
    if user_input != "":
        print(user_input)

menubar = tk.Menu(win)
dropDown = tk.Menu(menubar, tearoff = 0)
dropDown.add_command(label = "Do something", command = take_user_input_for_something)

# this entry field is not really needed her.
# however I noticed you did not define this widget correctly
# so I put this in to give you an example.
my_entry = tk.Entry(win)
my_entry.pack()

menubar.add_cascade(label = "Drop Down", menu = dropDown)
win.config(menu = menubar)

win.mainloop()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get Swagger UI's Parameter to be Dropdown menu instead of Text Input

how to take user input in Array using java?

How to take user input in jshell script?

How To Control Input Type Dropdown Menu With Jquery

Filter an Array based off user input string and menu dropdown items

how to get dropdown-menu item value and apend to text input?

how to take user input and convert to uppercase in assembly

How to allow user input on tkinter?

Is there any possible way to take user input in the case of enum datatype

How to change text color on OnMouseHover in a Dropdown Menu

AngularJS - Fill input text field with dropdown menu

How to update any text filed when the user is select an option from a dropdown-menu?

How take *args input from user in a function

NiFi: Add dropdown menu for user input

How to take user voice input in applescript

How to take input from user and change directory

How to take array size of length as user input?

How to take the element from menu dropdown in Selenium C#?

Manipulating user input from tkinter text widget

Is it possible for Pandoc to take text as an input argument rather than an input file?

Is it possible to take user input, and ask different question depending on the response?

How to take user input in node js?

How to take user input 'XXX' to end?

How can I better code a way to take the user back to the "menu" if a certain input is already in the csv file?

Java how to take user input

Is it possible to style the text that the user input in a contactform

Is it possible to style the text font that the user input in a contactform

Tkinter dropdown menu not retracting

Tkinter - How to update text after select option in dropdown menu?