Advertisement
Guest User

Untitled

a guest
Dec 25th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import colorchooser
  3.  
  4. color = 'red'
  5. start = False
  6.  
  7. def paint_rect(event):
  8.     if hasattr(event.widget, 'find_closest'):
  9.         tags = event.widget.find_closest(event.x, event.y)
  10.         for tag in tags:
  11.             c.itemconfig(tag, fill=color, width=3)
  12.  
  13. def rect():
  14.     x = 0
  15.     x1 = 10
  16.     y = 0
  17.     y1 = 10
  18.     tag = '1'
  19.  
  20.     while x1 != 1450 and y1 != 910:
  21.         c.create_rectangle(x, y, x1, y1, tag=tag, fill='white')
  22.         x = x + 10
  23.         x1 = x1 + 10
  24.         tag = str(int(tag) + 1)
  25.         if x1 == 1450:
  26.             x = 0
  27.             x1 = 10
  28.             y = y + 10
  29.             y1 = y1 + 10
  30.  
  31. def binder(event):
  32.     if hasattr(event.widget, 'find_withtag'):
  33.         tag = event.widget.find_withtag("current")
  34.         c.itemconfig(tag, fill=color, width=3)
  35.  
  36. def get_color():
  37.     global color
  38.     color = colorchooser.askcolor()[1]
  39.  
  40. def start_game():
  41.     global c
  42.     c = Canvas(w, width=1450, height=910)
  43.     c.pack()
  44.     button = Button(w, width=12, height=2, text='Выход', bg='red', fg='black', command=lambda: w.destroy())
  45.     button.place(x=0, y=0)
  46.     button = Button(w, width=12,height=2, text='Цвет', bg='red', fg='black', command=get_color)
  47.     button.place(x=100, y=0)
  48.     rect()
  49.     c.bind_all('<Button-1>', binder)
  50.     c.bind_all("<B1-Motion>", paint_rect)
  51.  
  52.  
  53. def main():
  54.     global w
  55.     w = Tk()
  56.     w.attributes('-fullscreen',True)
  57.     button = Button(w, width=12, height=2, text='Выход', bg='red', fg='black', command=lambda: w.destroy())
  58.     button.place(x=0, y=0)
  59.     button1 = Button(w, width=12, height=2, text='Начать', bg='red', fg='black', command=lambda: start_game())
  60.     button1.place(x=500, y=500)
  61.     w.mainloop()
  62.  
  63. if __name__ == '__main__':
  64.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement