Last active
May 22, 2017 05:03
-
-
Save mikkipastel/811b5af4bfed153c6a59bc3b2d4d209a to your computer and use it in GitHub Desktop.
Try to do python GUI by tkinter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import * | |
from tkinter.ttk import * | |
class Application(Frame): | |
def __init__(self, master): | |
# initialize frame | |
Frame.__init__(self, master) | |
self.grid() | |
self.create_widgets() | |
def create_widgets(self): | |
# add Entry | |
self.entry = Entry(self, width=20) | |
self.entry.grid(column=0, row=1) | |
# add Radiobutton | |
food = [("chicken", "chicken"), ("pork", "pork"), ("meat", "meat")] | |
cnt = 1 | |
for text, mode in food: | |
self.radio = Radiobutton(self, text=text, variable=var, value=mode, width=5) | |
self.radio.grid(column=cnt, row=1) | |
cnt+=1 | |
# add button | |
self.button = Button(self) | |
self.button.grid() | |
self.button["text"] = "Print" | |
self.button["command"] = self.print_food | |
self.button.grid(column=2, row=2) | |
# print input | |
def print_food(self): | |
print(self.entry.get(), var.get()) | |
# for debug | |
if __name__=="__main__": | |
root = Tk() | |
root.title("Lebeller") | |
root.geometry("350x200") | |
var = StringVar() | |
app = Application(root) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment