1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #!/usr/bin/env python
# -*- coding: utf8 -*-
#
#
try:
import tkinter as tk
except:
import Tkinter as tk
def chtxt():
can.itemconfig(can.find_withtag(2), text="A ben oui")
def chcolor():
can.itemconfig(can.find_withtag(1), fill="red")
root = tk.Tk()
can = tk.Canvas(root, height=200, width=300, background="white")
can.create_rectangle(20, 20, 280, 180, fill="green")
can.create_text(100, 100, font="Arial 20 bold underline", text="Test")
can.pack()
tk.Button(root, text='Change text', command=chtxt).pack(side=tk.LEFT)
tk.Button(root, text='Change color', command=chcolor).pack(side=tk.LEFT)
tk.Button(root, text='Quit', command=root.quit).pack(side=tk.LEFT)
root.mainloop() |
Partager