70 likes | 88 Views
Tkinter. https://www.activestate.com/activetcl/downloads C:ActiveTclbin; ortam değişkenlerinde PATH ekliyoruz. C:Python34Script , ortam değişkenlerine ‘pip ‘ çalıştırmak için ekliyoruz. Hello World. from Tkinter import *
E N D
Tkinter • https://www.activestate.com/activetcl/downloads • C:\ActiveTcl\bin; ortam değişkenlerinde PATH ekliyoruz. • C:\Python34\Script , ortam değişkenlerine ‘pip ‘ çalıştırmak için ekliyoruz.
Hello World from Tkinter import * root = Tk(className ="My first GUI") #add a root window named Myfirst GUI foo = Label(root,text="Hello World") # add a label to root window foo.pack() root.mainloop()
Komponents • foo = Label(root,text="SomeLabeltext here") # add a labeltorootwindow • foo = Message(root,text=" SomeLongtext here")# usedinstead of label, whenthetext is long • foo = Button(root,text="Login",command= function_when_pressed) # button - discussed in nextexample • foo = Entry(root,textvariable=svalue) # adds a textareawidget • foo = Checkbutton(root,text="Tick Me", variable=ticked_yes) # tickbutton • foo = Radiobutton(root,text="Option1",variable=opt1, value="option1") #radiobutton • foo = Scale(root, label="Volume Control",variable=volume, from =0, to=10, tickinterval=2, orient='vertical', command=on_slide) # slider
Button Veri Girişi fromTkinterimport * root = Tk(className ="My first GUI") svalue = StringVar() # definesthewidgetstate as string w = Entry(root,textvariable=svalue) # adds a textareawidget w.pack() def act(): print "youentered" print '%s' % svalue.get() foo = Button(root,text="Press Me", command=act) foo.pack() root.mainloop()
Örnek1 fromTkinterimport * def hello(): print "Hello World" # Main rootwindow root = Tk() # A buttonwith a callbackfunction Button(root, text="Press here", command=hello).pack() # .pack() method is necessarytomakethebuttonappear # Eventloop root.mainloop()
Örnek2 from tkinter import Tk, Label, Button class MyFirstGUI: def __init__(self, master): self.master = master master.title("A simple GUI") self.label = Label(master, text="This is our first GUI!") self.label.pack() self.greet_button = Button(master, text="Greet", command=self.greet) self.greet_button.pack() self.close_button = Button(master, text="Close", command=master.quit) self.close_button.pack() def greet(self): print("Greetings!") root = Tk() my_gui = MyFirstGUI(root) root.mainloop()