Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter import colorchooser
- color = 'red'
- start = False
- def paint_rect(event):
- if hasattr(event.widget, 'find_closest'):
- tags = event.widget.find_closest(event.x, event.y)
- for tag in tags:
- c.itemconfig(tag, fill=color, width=3)
- def rect():
- x = 0
- x1 = 10
- y = 0
- y1 = 10
- tag = '1'
- while x1 != 1450 and y1 != 910:
- c.create_rectangle(x, y, x1, y1, tag=tag, fill='white')
- x = x + 10
- x1 = x1 + 10
- tag = str(int(tag) + 1)
- if x1 == 1450:
- x = 0
- x1 = 10
- y = y + 10
- y1 = y1 + 10
- def binder(event):
- if hasattr(event.widget, 'find_withtag'):
- tag = event.widget.find_withtag("current")
- c.itemconfig(tag, fill=color, width=3)
- def get_color():
- global color
- color = colorchooser.askcolor()[1]
- def start_game():
- global c
- c = Canvas(w, width=1450, height=910)
- c.pack()
- button = Button(w, width=12, height=2, text='Выход', bg='red', fg='black', command=lambda: w.destroy())
- button.place(x=0, y=0)
- button = Button(w, width=12,height=2, text='Цвет', bg='red', fg='black', command=get_color)
- button.place(x=100, y=0)
- rect()
- c.bind_all('<Button-1>', binder)
- c.bind_all("<B1-Motion>", paint_rect)
- def main():
- global w
- w = Tk()
- w.attributes('-fullscreen',True)
- button = Button(w, width=12, height=2, text='Выход', bg='red', fg='black', command=lambda: w.destroy())
- button.place(x=0, y=0)
- button1 = Button(w, width=12, height=2, text='Начать', bg='red', fg='black', command=lambda: start_game())
- button1.place(x=500, y=500)
- w.mainloop()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement