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 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| from tkinter import *
def toplevel():
top=Toplevel(root)
frame = Frame(top)
frame.pack(padx=10, pady=100)
can = Canvas(frame, background='yellow')
can.grid(row=0, column=0)
frame_b = Frame(can)
#Generation des boutons
for ligne in range(taille_y):
for colonne in range(taille_x):
button = Button(frame_b, borderwidth=1, background='white', width=2, height=1)
button['command'] = lambda button=button: button.configure(background = 'black')
button.grid(row=ligne, column=colonne)
can.create_window((0,0), window=frame_b, anchor=NW)
frame_b.update_idletasks()
bbox = can.bbox(ALL)
w, h = bbox[2]-bbox[1], bbox[3]-bbox[1]
dw, dh = int((w/taille_x) * 20), int((h/taille_y) * 20)
can.configure(scrollregion=bbox, width=dw, height=dh)
root=Tk()
x = StringVar(root)
y = StringVar(root)
x.set("10") """Valeur de base"""
y.set("10") """Valeur de base"""
E1=Entry(textvariable=x, width=7,justify=CENTER)
E2=Entry(textvariable=y, width=7,justify=CENTER)
E1.pack(side = RIGHT)
E2.pack(side = RIGHT)
go=Button(root, text="lancer", command=toplevel)
go.pack()
taille_x = int(E1.get())
taille_y = int(E2.get())
root.mainloop() |
Partager