IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

pourquoi le bouton ne monte pas avec le reste du canvas?


Sujet :

Tkinter Python

  1. #1
    Membre à l'essai
    Homme Profil pro
    Enseignant
    Inscrit en
    Novembre 2018
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Novembre 2018
    Messages : 16
    Points : 15
    Points
    15
    Par défaut pourquoi le bouton ne monte pas avec le reste du canvas?
    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.

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 283
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 283
    Points : 36 770
    Points
    36 770
    Par défaut
    Salut,

    On ne bouge pas le rectangle vert, on change la "vue" affichée par le Canvas sur le graphique (plus grand que ses dimensions "physiques").
    Le Button n'est pas un item affiché par le Canvas puisque vous avez utilisé .place pour l'afficher dans le rectangle délimité par le Canvas. Pour qu'il le soit, il faudrait utiliser .create_window (méthode du Canvas).

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Membre à l'essai
    Homme Profil pro
    Enseignant
    Inscrit en
    Novembre 2018
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Novembre 2018
    Messages : 16
    Points : 15
    Points
    15
    Par défaut
    Merci beaucoup.
    L'explication est très claire.
    Voici la version corrigée qui effectivement fonctionne:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    # 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,200,700,500, 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.can.create_window(630,150,anchor='nw',window=self.Valider_Points_S)
            self.can.create_window(630,630,anchor='nw',window=self.Valider_Points_N)
            #self.Valider_Points_S.place(x=630, y=630, width=60, height=20)
    Merci encore.

Discussions similaires

  1. [HTML] Ancre liée à formulaire fonctionne pas avec certains boutons "submit" sur ie6
    Par 12monkeys dans le forum Balisage (X)HTML et validation W3C
    Réponses: 9
    Dernier message: 28/02/2008, 21h30
  2. Réponses: 2
    Dernier message: 31/07/2006, 08h48
  3. Mon script fonctionne avec un bouton, mais pas avec l'image!
    Par julien.63 dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 12/04/2006, 16h26
  4. fonctionne avec les sessions pas avec le reste
    Par hugo69 dans le forum Langage
    Réponses: 6
    Dernier message: 22/11/2005, 09h38
  5. [xhtml][css] bouton du form ne marche pas avec IE6
    Par chinouk dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 14/06/2005, 14h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo