Download presentation
Presentation is loading. Please wait.
Published byDulcie Hicks Modified over 8 years ago
1
Using TKINTER For Better Graphic Tkinter module offers more functions: Button Widget: from tkinter import * tk =Tk() btn=Button(tk, text=‘Click me’) btn.pack()
2
To Make button work: def hello(): print(‘hello there’) from tkinter import * tk =Tk() btn=Button(tk, text=‘Click me’, command=‘hello’) btn.pack()
3
Using Named Parameters: def person(width, height): Print (‘I am %s feet wide, %s feet high’ %(width, height)) Person(4,3) Person(height=3, width=4)
4
Draw a Canvas, Line, Boxes, Rectangle canvas = Canvas(tk, width=500, height=500) canvas.pack() canvas.create_line(0,0,200,200) canvas.create_rectangle(10,10,50,50) canvas.create_rectangle(10,10,50,50, fill=fill_color) canvas.create_arc(10,10,200,100, extent=180, style=ARC) canvas.create_polygon(10,10,100,10,100,110, fill=‘’, outline=‘black’) canvas.create_text(150, 100, text="Amazing!", fill="purple", font="Helvetica 26 bold underline")
5
Get Color from tkinter import * from tkinter.colorchooser import * color=askcolor()
6
Display Image from tkinter import * tk = Tk() canvas=Canvas(tk, width=500, height=500) canvas.pack() my_image=PhotoImage(file='c:\\python\lesson2\\giphy_s.gif') canvas.create_image(0,0,anchor=NW, image=my_image)
7
Basic Animation import time from tkinter import * tk = Tk() canvas=Canvas(tk, width=500, height=500) canvas.pack() my_image=PhotoImage(file='c:\\python\lesson2\\giphy_s.gif') canvas.create_image(0,0,anchor=NW, image=my_image) for x in range(0,60): canvas.move(1,5,0) tk.update() time.sleep(0.05)
8
Event Binding Events: things that occur while a program is running, such as pressing a key, moving the mouse. Events:,, canvas.bind_all(‘ ’, function)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.