I am a beginner python user who decided to make a small GUI using tkinter that takes 3 inputs from users (potential restaurants) and after clicking a button, randomly outputs one of the restaurants. I keep getting a syntax error and believe it is related to my buttonfunc or the command that calls it. This code doesn’t yet include anywhere to output the restaurant on the GUI. Any help would be greatly appreiciated
# Python Project Random Selector
import random
import tkinter as tk
root = tk.Tk()
def buttonfunc():
all_rest = [entrystr1.get(), entrystr2.get(), entrystr3.get()]
randomrest = random.choice(all_rest)
print(randomrest)
root.geometry("800x500")
root.title("Random Choice GUI")
label = tk.Label(root, text="Enter 3 of your favourite restaurants and seperate them by a comma (,): ", font=('Arial',16))
label.pack(padx=20, pady=20)
entrystr1 = tk.StringVar(value = 'type the first restaurant name here')
choice1 = tk.Entry(root, textvariable = entrystr1)
choice1.pack()
entrystr2 = tk.StringVar(value = 'type the second restaurant name here')
choice2 = tk.Entry(root, textvariable = entrystr2)
choice2.pack()
entrystr3 = tk.StringVar(value = 'type the third restaurant name here')
choice3 = tk.Entry(root, textvariable = entrystr3)
choice3.pack()
enterbtn = tk.Button(root, text="Enter", command=lambda: buttonfunc, font=('Arial',14) )
enterbtn.pack()
root.mainloop()
I tried many times to change the variables within my buttonfunc, however, that would not work. I also tried to reduce my code to just one entry box to see if something was wrong with the repeating code. That also didn’t work.
t ta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.