Advertisement
Bkmz

Untitled

Sep 25th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3.  
  4. from Tkinter import Tk, Canvas
  5.  
  6.  
  7. class App:
  8.     def __init__(self, master):
  9.        
  10.         self.master = master
  11.        
  12.         self.width  = {"start": 0, "end": 640}
  13.         self.height = {"start": 0, "end": 480}
  14.        
  15.         self.canvas = Canvas(master)
  16.        
  17.         self.canvas.configure({"bg": "white"})
  18.         self.canvas.pack({"fill": "both", "expand": True})
  19.        
  20.        
  21.         # Tk bindings
  22.         self.__bindings(master)
  23.     def __update_coords(self, event):
  24.         # bind event, to update coordinates
  25.         self.width['end']  = event.width
  26.         self.height['end'] = event.height
  27.        
  28.         self.canvas.update_idletasks()
  29.        
  30.         self.__draw()
  31.        
  32.        
  33.     def __draw(self, event=None):
  34.         self.canvas.delete("diagonal")
  35.         self.canvas.create_line(
  36.                                 self.width['start'],
  37.                                 self.height['start'],
  38.                                 self.width['end'],
  39.                                 self.height['end'],
  40.                                 tags="diagonal")
  41.        
  42.        
  43.        
  44.        
  45.     def __bindings(self, master):
  46.         # binding master window resize
  47.         master.bind("<Configure>", self.__update_coords)
  48. #        master.bind("<Configure>", self.__draw)
  49.        
  50.  
  51. root = Tk()
  52. root.title("MachineGraphics. Lab2. Variant 2")
  53. root.geometry("640x480-0+100")
  54.  
  55. app = App(root)
  56.  
  57. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement