![]() |
[Tkinter] Choose from dropdown list and then do something? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Choose from dropdown list and then do something? (/thread-18955.html) |
Choose from dropdown list and then do something? - Selfiatus1 - Jun-07-2019 Hi, there is an error with my if function... It just woun't write to the document when I press the button "Generate". I only want to write to a document, a word that is based on the dropdown list, when I press the button "Generate"? How should I code that? import tkinter as tk from docx import Document HEIGHT = 500 WIDTH = 600 root = tk.Tk() root.title("Generator") canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH) canvas.pack() background_image = tk.PhotoImage(file='bg123.png') background_label = tk.Label(root, image=background_image) background_label.place(x=-6, y=-6) #dropdown part # Create a Tkinter variable tkvar = tk.StringVar(root) choices = { 'broker','consultant','recruit'} tkvar.set('broker') # set the default option popupMenu = tk.OptionMenu(root, tkvar, *choices) popupMenu.place(x=260,y=95) def helloCallBack(): if tkvar == 'broker': document = Document() document.add_heading("broker") document.save('0034.docx') button = tk.Button(text="Generate", font=40, command=helloCallBack) button.place(x=230, y=380) root.mainloop()Kr. Selfiatus1 RE: Choose from dropdown list and then do something? - Yoriz - Jun-07-2019 change ... def helloCallBack(): if tkvar == 'broker': ...to ... def helloCallBack(): if tkvar.get() == 'broker': ... RE: Choose from dropdown list and then do something? - Selfiatus1 - Jun-07-2019 (Jun-07-2019, 07:53 PM)Yoriz Wrote: change THANK YOU! |