Tkinter Canvas, Button & Text

 


Sintax :

w = canvas(parent, options)


Contoh 1 :

from tkinter import *   

top = Tk()  

top.geometry("200x200")  

#creating a simple canvas  

c = Canvas(top,bg = "pink",height = "200")  

c.pack()  

top.mainloop()


Contoh 2 :

from tkinter import *   

top = Tk()  

top.geometry("200x200")  

#creating a simple canvas  

c = Canvas(top,bg = "pink",height = "200",width = 200)  

arc = c.create_arc((5,10,150,200),start = 0,extent = 150, fill= "white")  

c.pack()  

top.mainloop() 


Tkinter Button

Sintax :

W = Button(parent, options)


Contoh 1 :

#python application to create a simple button  

from tkinter import *   

top = Tk()  

top.geometry("200x100")  

b = Button(top,text = "Simple")  

b.pack()  

top.mainaloop()  



Contoh 2 :

from tkinter import *   

top = Tk()  

top.geometry("200x100")  

def fun():  

    messagebox.showinfo("Hello", "Red Button clicked")  

b1 = Button(top,text = "Red",command = fun,activeforeground = "red",activebackground = "pink",pady=10)  

b2 = Button(top, text = "Blue",activeforeground = "blue",activebackground = "pink",pady=10)  

b3 = Button(top, text = "Green",activeforeground = "green",activebackground = "pink",pady = 10)  

b4 = Button(top, text = "Yellow",activeforeground = "yellow",activebackground = "pink",pady = 10)  

b1.pack(side = LEFT)  

b2.pack(side = RIGHT)  

b3.pack(side = TOP)  

b4.pack(side = BOTTOM)  

top.mainloop()    

  


Tkinter Text

Sintax :

w = Text(top, options)


Contoh :

from tkinter import *  
top = Tk()  
text = Text(top)  
text.insert(INSERT, "Name.....")  
text.insert(END, "Salary.....")  
text.pack()  
text.tag_add("Write Here", "1.0", "1.4")  
text.tag_add("Click Here", "1.8", "1.13")  
text.tag_config("Write Here", background="yellow", foreground="black")  
text.tag_config("Click Here", background="black", foreground="white")  
top.mainloop()