0

On a basic launcher-programm (recently corrected, see Scrollbar - make the background move but not the forderground), I have the following problem : buttons disappear when I use the scrollbar. Actually they are still there and I can click on the buttons, but they are now visible. If the mouse cursor goes on the button position and then leave this area, the button reappear. I think the problem is the update of the GUI. That's why I use a lot of update in the programm (probably too much) but it still doesn't work.

Here is my code :

# -*-coding:Utf-8 -*-
from __future__ import unicode_literals

import Tkinter
import ImageTk
import Image



class Interface(Tkinter.Tk) :
    def __init__(self, parent) :
        Tkinter.Tk.__init__(self, parent)
        self.parent = parent
        self.initialize()

# Creation of the widgets
    def initialize(self) :
    # Fenetre principale
        self.minsize(437, 98)
        # Scrollbars working on principal Canvas self.c
        self.ascenseur_y = Tkinter.Scrollbar(self, orient=Tkinter.VERTICAL)
        self.ascenseur_x = Tkinter.Scrollbar(self, orient=Tkinter.HORIZONTAL)
        self.ascenseur_y.grid(row=0, column=1, sticky="ns")
        self.ascenseur_x.grid(row=1, column=0, sticky="ew")

        # Canvas self.c - Frame self.fr and label self.bl are in self.c
        self.c = Tkinter.Canvas(self, yscrollcommand=self.ascenseur_y.set, xscrollcommand=self.ascenseur_x.set, bg="white", highlightthicknes=0)
        self.c.grid(row=0, column=0, sticky="news")
        self.c.bind('<Configure>', self.dimensionner)

        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)

        self.ascenseur_x.config(command=self.c.xview)
        self.ascenseur_y.config(command=self.c.yview)

        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)

    # Invisible Frame to bind Mousewheel event with vertical scrollbar
        self.fr = Tkinter.Frame(self.c)
        self.fr.pack(expand=True, fill="both")
        self.fr.bind_all("<MouseWheel>", self._on_mousewheel_haupt)

    # Def Label with background-picture. all other widgets but the scrollbars are in self.bl
        self.apercu_logo="Logo.png"
        self.photo = ImageTk.PhotoImage(Image.open(self.apercu_logo))
        self.bl = Tkinter.Label(self.c, image=self.photo, bg="white")

        self.image_y = self.winfo_height()/2
        self.image_x = self.winfo_width()/2
        self.c.create_window(450/2, 300/2, window=self.bl, height=500, width=800)
        self.bl.update_idletasks()

    # Button "start pdf2pptx"
        self.bouton_pdf2pptx = Tkinter.Button(self.bl, width=13, text=u"Pdf2pptx", command=self.ButtonPdf2pptx, anchor="center", cursor="hand2", padx=0)
        self.bouton_pdf2pptx.grid(column=0, row=0, padx=10)
        self.bouton_pdf2pptx.bind("<Return>", self.EnterPdf2pptx)
        self.bouton_pdf2pptx.focus_set()

    # Button "start xls2inp"
        self.bouton_xls2inp = Tkinter.Button(self.bl, width=13, text=u"xls2inp", command=self.ButtonXls2inp, anchor="center", cursor="hand2", padx=0)
        self.bouton_xls2inp.grid(column=1, row=0, padx=10)
        self.bouton_xls2inp.bind("<Return>", self.EnterXls2inp)

    # Button "start Zeichen ersetzer"
        self.bouton_ZeichenErsetzer = Tkinter.Button(self.bl, width=13, text=u"Zeichen ersetzer", command=self.ButtonZeichenErsetzer, anchor="center", cursor="hand2", padx=0)
        self.bouton_ZeichenErsetzer.grid(column=2, row=0, padx=10)
        self.bouton_ZeichenErsetzer.bind("<Return>", self.EnterZeichenErsetzer)


    # Configuration rows/columns - in self.bl

        self.bl.grid_rowconfigure(0, weight=1, pad=100, minsize=50)

        self.bl.grid_columnconfigure(0, weight=1, pad=30, minsize=140)
        self.bl.grid_columnconfigure(1, weight=1, pad=30, minsize=140)
        self.bl.grid_columnconfigure(2, weight=1, pad=30, minsize=140)

    # Logo of the main window
        self.iconbitmap("IcoKAG.ico")

# Options of the main window
        # Resizable
        self.resizable(True, True)
        # Principal Canvas and config of the scrollbars
        self.image_y = self.winfo_height()/2
        self.image_x = self.winfo_width()/2
        self.c.create_window(self.image_x, self.image_y, window=self.fr)
        self.fr.update_idletasks()

        # Min size of main window
        self.minsize(200, 100)

        # Size of main window at the opening
        self.geometry("500x300")

        if self.winfo_width() < 437 :
            self.bl.grid_columnconfigure(0, weight=1, pad=30, minsize=self.winfo_width()/3)
            self.bl.grid_columnconfigure(1, weight=1, pad=30, minsize=self.winfo_width()/3)
            self.bl.grid_columnconfigure(2, weight=1, pad=30, minsize=self.winfo_width()/3)
        else :
            self.bl.grid_columnconfigure(0, weight=1, pad=30, minsize=140)
            self.bl.grid_columnconfigure(1, weight=1, pad=30, minsize=140)
            self.bl.grid_columnconfigure(2, weight=1, pad=30, minsize=140)

        if self.winfo_height() >= 300 and self.winfo_width() >= 500 :
            self.SR = (0, 0, self.photo.width(), self.photo.height())
            self.SRL = list(self.SR)
            self.SRL[2] = self.winfo_width() - 16
            self.SRL[3] = self.winfo_height() - 16
            self.c.config(scrollregion=tuple(self.SRL))
            self.update()
        elif self.winfo_height() < 300 and self.winfo_width() >= 500 :
            self.SR = (0, 0, self.photo.width(), self.photo.height())
            self.SRL = list(self.SR)
            self.SRL[2] = self.winfo_width() - 16
            self.SRL[3] -= 16
            self.c.config(scrollregion=tuple(self.SRL))
            self.update()
        elif self.winfo_height() >= 300 and self.winfo_width() < 500 :
            self.SR = (0, 0, self.photo.width(), self.photo.height())
            self.SRL = list(self.SR)
            self.SRL[2] -= 16
            self.SRL[3] = self.winfo_height() - 16
            self.c.config(scrollregion=tuple(self.SRL))
            self.update()
        else :
            self.SR = (0, 0, self.photo.width(), self.photo.height())
            self.SRL = list(self.SR)
            self.SRL[2] -= 16
            self.SRL[3] -= 16
            self.c.config(scrollregion=tuple(self.SRL))
            self.update()
        # Make sure all widgets are updated
        self.update()
        self.bl.update_idletasks()




# Fonctions 

    def dimensionner(self, event):
        """ Gestion du redimentionnement de la taille de la fenêtre :
            Repositionne l'image de fond
            Modifie la taille des lignes/colonnes
            Regle les scrollbars """
    # Scrollbars options
        if self.winfo_width() < 437 :
            self.bl.grid_columnconfigure(0, weight=1, pad=30, minsize=self.winfo_width()/3)
            self.bl.grid_columnconfigure(1, weight=1, pad=30, minsize=self.winfo_width()/3)
            self.bl.grid_columnconfigure(2, weight=1, pad=30, minsize=self.winfo_width()/3)
            self.update()
            self.c.update_idletasks()
        else :
            self.bl.grid_columnconfigure(0, weight=1, pad=30, minsize=140)
            self.bl.grid_columnconfigure(1, weight=1, pad=30, minsize=140)
            self.bl.grid_columnconfigure(2, weight=1, pad=30, minsize=140)
            self.update()
            self.c.update_idletasks()

        if self.winfo_height() >= 300 and self.winfo_width() >= 500 :
            self.SR = (0, 0, self.photo.width(), self.photo.height())
            self.SRL = list(self.SR)
            self.SRL[2] = self.winfo_width() - 16
            self.SRL[3] = self.winfo_height() - 16
            self.c.config(scrollregion=tuple(self.SRL))
            self.update()
            self.c.update_idletasks()
        elif self.winfo_height() < 300 and self.winfo_width() >= 500 :
            self.SR = (0, 0, self.photo.width(), self.photo.height())
            self.SRL = list(self.SR)
            self.SRL[2] = self.winfo_width() - 16
            self.SRL[3] = 300 - 16
            self.c.config(scrollregion=tuple(self.SRL))
            self.update()
            self.c.update_idletasks()
        elif self.winfo_height() >= 300 and self.winfo_width() < 500 :
            self.SR = (0, 0, self.photo.width(), self.photo.height())
            self.SRL = list(self.SR)
            self.SRL[2] = 500 - 16
            self.SRL[3] = self.winfo_height() - 16
            self.c.config(scrollregion=tuple(self.SRL))
            self.update()
            self.c.update_idletasks()
        else :
            self.c.config(scrollregion=(0, 0, 484, 284))
            self.update()
            self.c.update_idletasks()

    # Center the Background-label
        if self.winfo_height() >= 300 and self.winfo_width() >= 500 :
            self.image_y = self.winfo_height()/2
            self.image_x = self.winfo_width()/2
            self.c.create_window(self.image_x, self.image_y, window=self.bl, height=self.winfo_height(), width=self.winfo_width())
            self.update()
            self.c.update_idletasks()
        elif self.winfo_height() < 300 and self.winfo_width() >= 500 :
            self.image_y = 300/2
            self.image_x = self.winfo_width()/2
            self.c.create_window(self.image_x, self.image_y, window=self.bl, height=300, width=self.winfo_width())
            self.update()
            self.c.update_idletasks()
        elif self.winfo_height() >= 300 and self.winfo_width() < 500 :
            self.image_y = self.winfo_height()/2
            self.image_x = 500/2
            self.c.create_window(self.image_x, self.image_y, window=self.bl, height=self.winfo_height(), width=500)
            self.update()
            self.c.update_idletasks()
        else :
            self.image_y = 300/2
            self.image_x = 500/2
            self.c.create_window(self.image_x, self.image_y, window=self.bl, height=300, width=500)
            self.update()
            self.c.update_idletasks()



    def _on_mousewheel_haupt(self, event):
        """ Bind mousewheel to y-scrollbar """
        self.c.yview_scroll(-1*(event.delta/120), "units")

    def ButtonPdf2pptx(self) :
        pass

    def EnterPdf2pptx(self, event) :
        self.ButtonPdf2pptx()

    def ButtonXls2inp(self) :
        pass

    def EnterXls2inp(self, event) :
        self.ButtonXls2inp()

    def ButtonZeichenErsetzer(self) :
        pass

    def EnterZeichenErsetzer(self, event) :
        self.ButtonZeichenErsetzer()



# Main window is build
if __name__ == "__main__" :
    appLauncher = Interface(None)
    appLauncher.title(u"Programm-launcher - Kämmerer AG")
    appLauncher.mainloop()

Does someone have an idea ?

Tanks

4

1 回答 1

0

我无法复制你的结果。我看到三个按钮,它们永远不会消失。

您对使用太多更新是正确的。您不应该需要对updateupdate_idletaskin 的任何调用dimensionner——该函数仅作为事件的结果被调用,因此在调用该函数时 UI 应该已经是最新的。

此外,您有很多代码没有按照您的想法执行。例如:

self.bl.grid_rowconfigure(0, weight=1, pad=100, minsize=50)

这只会影响放置在按钮的按钮的子项。您的代码没有在按钮内放置任何小部件(这非常不寻常)。当您调用grid_rowconfigureandgrid_columnconfigure时,您正在配置小部件内部的行和列,而不是包含小部件的行和列。

于 2013-07-26T13:59:24.730 回答