How to get output result from selecting two dropdown menu options in tkinter

0 votes

if i choose a value from first combobox menu, then the next combobox menu will show only values that inside the first selected combobox value category.

and as soon as i click second combobox menu i want my result "Hello" as a output as a text label.

The code is as below-

import tkinter as tk

Classid = ["A", "B", "C"]

subclassid = [["X", "Y", "Z"],["X", "Y", "Z"], ["X", "Y", "Z"]]

root = tk.Tk()

canvas = tk.Canvas(root, height = 500, width = 500, bg='white')

canvas.pack()

tkClassid = tk.StringVar(root)

tkClassid.set("Choose")

tksubid = tk.StringVar(root)

tksubid.set('Drug Class')

popupMenu1 = tk.OptionMenu(canvas, tkClassid, Classid)

popupMenu1.pack()

popupMenu2 = tk.OptionMenu(canvas, tksubid, [])

popupMenu2.pack()

def change_dropdown(*args):

    print("Chosen Class " + tkClassid.get())

        for i in range(len(Classid)):

            if tkClassid.get() == Classid[i]:

                popupMenu2["menu"].delete(0, "end")

                    for item in subclassid[i]:

                        popupMenu2['menu'].add_command(label=item, command=tk_setit(tksubid, item))

tkClassid.trace('w', change_dropdown)

def resultout():

    myLabel = Label(root, text=clicked.get()).pack()

        if x=='A' and y=='X':

            print('Hello')

clicked = StringVar(root)

myButton= Button(root,text='Result', command=resultout).pack()

root.mainloop()
Sep 4, 2020 in Python by Charitra
• 120 points
2,043 views

Hi, @Charitra

I think there is some problem with the for loops and if statement inside function. Please check that.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

–1 vote
1 answer

Pyspark rdd How to get partition number in output ?

The glom function is what you are looking for: glom(self): ...READ MORE

answered Jan 8, 2019 in Python by Omkar
• 69,210 points
1,780 views
0 votes
1 answer

How to get textual output when using exceptions in Python?

Hi, the answer is pretty simple.  Without the ...READ MORE

answered Jan 17, 2019 in Python by Nymeria
• 3,540 points
346 views
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer

How to output text from database with line breaks in a django template?

Hello @kartik, Use linebreaks or linebreaksbr filter: {{ text|linebreaks }} Or surround the text ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,740 points
7,762 views
0 votes
1 answer

How to get value from form field in django framework?

Hello @kartik, Using a form in a view can ...READ MORE

answered Jun 30, 2020 in Python by Niroj
• 82,740 points
5,295 views
0 votes
0 answers

Help: Receive data from tkinter gui and perform mathematical operations between lists

hello friends, I have been working on a ...READ MORE

Nov 4, 2020 in Python by Jessica
• 120 points
369 views
0 votes
1 answer

Need help with Tkinter window formatting using Python

Tkininter comes with the columnspan argument to span the labels ...READ MORE

answered Sep 7, 2018 in Python by aryya
• 7,440 points
349 views
0 votes
1 answer

Is there a way of using .lower more effectively in tkinter?

Here is a simple function and some ...READ MORE

answered Sep 25, 2018 in Python by Priyaj
• 58,080 points
1,327 views
0 votes
1 answer

What does enumerate mean?

The enumerate() function adds a counter to ...READ MORE

answered Oct 11, 2018 in Python by SDeb
• 13,300 points
217 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP