Advertisement
here2share

Tk_Shapes2Canvas.py

Feb 19th, 2015
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5. ZetCode Tkinter tutorial
  6.  
  7. In this script, we draw basic
  8. shapes on the canvas.
  9.  
  10. author: Jan Bodar
  11. last modified: January 2011
  12. website: www.zetcode.com
  13. """
  14.  
  15. from Tkinter import Tk, Canvas, Frame, BOTH
  16.  
  17.  
  18. class Example(Frame):
  19.  
  20.     def __init__(self, parent):
  21.         Frame.__init__(self, parent)  
  22.          
  23.         self.parent = parent        
  24.         self.initUI()
  25.        
  26.     def initUI(self):
  27.      
  28.         self.parent.title("Shapes")        
  29.         self.pack(fill=BOTH, expand=1)
  30.  
  31.         canvas = Canvas(self)
  32.         canvas.create_oval(10, 10, 80, 80, outline="red",
  33.             fill="green", width=2)
  34.         canvas.create_oval(110, 10, 210, 80, outline="#f11",
  35.             fill="#1f1", width=2)
  36.         canvas.create_rectangle(230, 10, 290, 60,
  37.             outline="#f11", fill="#1f1", width=2)
  38.         canvas.create_arc(30, 200, 90, 100, start=0,
  39.             extent=210, outline="#f11", fill="#1f1", width=2)
  40.            
  41.         points = [150, 100, 200, 120, 240, 180, 210,
  42.             200, 150, 150, 100, 200]
  43.         canvas.create_polygon(points, outline='red',
  44.             fill='green', width=2)
  45.        
  46.         canvas.pack(fill=BOTH, expand=1)
  47.  
  48.  
  49. def main():
  50.  
  51.     root = Tk()
  52.     ex = Example(root)
  53.     root.geometry("330x220+300+300")
  54.     root.mainloop()  
  55.  
  56.  
  57. if __name__ == '__main__':
  58.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement