#!/usr/bin/python #import modules from Tkinter import * import random #create window root= Tk() #variable setting (StringVar) and list current=StringVar() lunch=['Red Rossa', 'Jasons Deli', 'Jethros','Pancheros','NYC Pizza','HyVee','Jimmy Johns','Monterrey'] #window setting (title, size) root.title("Lunch Picker") root.resizable(width='FALSE', height='FALSE') root.wm_geometry("%dx%d%+d%+d" % (200, 100, 100, 100)) #button widget with function to pick a lunch spot def picklunchspot(): chosen=random.choice(lunch) current.set(chosen) picklunchspot=Button(root,text="Pick Lunch Spot", command=picklunchspot) #displays the chosen spot by random chosenspot=Label(textvariable=current, fg ="dark blue",font=('times',20,'italic','bold')) #button widget with function to quit program def quit(): root.destroy() xout = Button(root,text="Quit", command=quit) #pack (add) the widgets into the window picklunchspot.pack() chosenspot.pack() xout.pack(side = BOTTOM) #draw the window, and start the 'application' root.configure() root.mainloop()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question