Bonjour à tous,
Voici mon programme dans lequel le rectangle vert et le bouton sont liés à self.can.
Pourquoi les ascenceurs de la fenêtre font-ils bouger le rectangle vert ET PAS le bouton?
Qu'est-ce qui m'échappe? Pourquoi le rectangle est-il bien lié au canvas et pas le bouton?
Dans l'attente de votre aide.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
import tkinter as tk
from tkinter import *
import os
from PIL import Image, ImageTk
import random
 
 
class Mon_Appli(tk.Frame):     # FENETRE PRINCIPALE
    def __init__(self,root):
        tk.Frame.__init__(self,root)
 
        self.can=tk.Canvas(self,bg="bisque")
        self.can.grid(row=0, column=0, sticky="nsew")
 
        self.xsb = tk.Scrollbar(self, orient="horizontal", command=self.can.xview) 
        self.ysb = tk.Scrollbar(self, orient="vertical", command=self.can.yview) 
        self.can.config(yscrollcommand=self.ysb.set, xscrollcommand=self.xsb.set) 
        self.can.config(scrollregion=(0,0,2000,2000)) 
 
        self.xsb.grid(row=1, column=0, sticky="ew") 
        self.ysb.grid(row=0, column=1, sticky="ns") 
 
        self.grid_rowconfigure(0, weight=1) 
        self.grid_columnconfigure(0, weight=1)
 
        #This is what enables scrolling with the mouse: 
        self.bind("<ButtonPress-1>", self.scroll_start) 
        self.bind("<B1-Motion>", self.scroll_move)
 
        # dessine un rectangle plein de couleur verte, de bord noir et d'épaisseur 2 x1/y1/x2/y2
        self.espace_encheres=self.can.create_rectangle (400,150,700,450, fill = "green", width = 2)
 
        self.Valider_Points_S=Button(self.can, text="Réponse",command="None",state = NORMAL)
        self.Valider_Points_N=Button(self.can, text="Réponse",command="None", state= NORMAL)
        self.Valider_Points_S.place(x=630, y=630, width=60, height=20)
 
################
    def scroll_start(self, event): 
        self.scan_mark(event.x, event.y) 
 
################
    def scroll_move(self, event): 
        self.scan_dragto(event.x, event.y, gain=1) 
 
#######################
######################################################## LANCEMENT PROGRAMME ########################################################
 
 
root = tk.Tk()#imposé
#To initialize tkinter, we have to create a Tk root widget, which is a window with a title bar and other decoration provided by the window manager.
#The root widget has to be created before any other widgets and there can only be one root widget. 
root.title('tournoi')#le nom par défaut de la fenêtre est tk. On le change en ce qu'on veut... 
root.state('zoomed')#plein écran
Mon_tournoi=Mon_Appli(root)#Mon_tournoi est une instance de la classe Mon_Appli avec ses propres variables
Mon_tournoi.pack(fill="both", expand=True)#Mon_tournoi remplit tout l'écran.
root.mainloop()#The window won't appear until we enter the Tkinter event loop; the script will remain in the event loop until we close the window.