# В третьем питоне она ЕСТЬ
from tkinter import *
def handle_key(event):
if event.char == 'q':
exit()
print(event.char)
def close_window(event):
exit(0)
# create the root window
root = Tk()
# modify the window
root.title("Tkinter rules!")
root.geometry("200x300")
root.bind("<Key>", handle_key);
root.bind("<Return>", close_window); # Enter
root.bind("<Escape>", exit); # Esc
# Start the window's event-loop
# root.focus_set()
w = Canvas(root, width=200, height=200)
w.create_line(0, 0, 200, 200, fill="red")
def draw_circle(event):
x, y = event.x, event.y
R = 5
w.create_oval(x - R, y - R, x + R, y + R,
fill="#00aa00", outline="black")
w.bind("<Button-1>", draw_circle);
w.place(x=0, y=0)#grid(row=0)
label = Label(root, text="Just a label")
label.place(x=0, y=200)#grid(row=1)
text_field = Entry(root, width=20)
text_field.place(x=70, y=200)#grid(row=1, column=1)
#for i in range(10):
but = Button(root,
text="Click me!",
width=10, height=1,
bg="blue",fg="white",font="Courier 20 bold"
)
def change_button_label(event):
print("Event!")
#but.text = text_field.get()
but["text"] = text_field.get()
#but["width"] = 50
but.bind("<Button-1>", change_button_label); # Left
but.bind("<Button-3>", lambda x : print(x)); # Right
but.place(x=0, y=220)#grid(row=2)
root.mainloop()
print('Hello!'); # Не выполнится до закрытия окна!