2013-07-26 4 views
0

기본 런처 - 프로그램 (최근 수정 됨, Scrollbar - make the background move but not the forderground 참조)에서 스크롤바를 사용할 때 버튼이 사라집니다. 사실 그들은 여전히 ​​거기에 있으며 버튼을 클릭 할 수 있지만 이제 볼 수 있습니다. 마우스 커서가 버튼 위치로 이동 한 후이 영역을 벗어나면 버튼이 다시 나타납니다. 문제는 GUI의 업데이트라고 생각합니다. 그래서 (아마도 너무 많은) programm에서 많은 업데이트를 사용하지만 여전히 작동하지 않습니다.스크롤 위젯이 보이지 않게 함

# -*-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() 

누군가가 생각이 있습니까 : 여기

내 코드?

탱크

+0

너비와 높이를 기반으로하는 모든 조건을 사용하여 달성하려는 작업은 무엇입니까 - 넓은 창과 큰 창에 대해 레이아웃이 다른가요? –

+0

그것은 스크롤바를위한 것입니다 :이 경우 스크롤바는 레이블 - 그림처럼 윈도우가 더 작을 때만 사용할 수 있습니다. 윈도우가 커지면 스크롤 바를 사용할 수 없지만 여전히 활성화됩니다. – Aegim

답변

0

결과를 복제 할 수 없습니다. 나는 3 개의 단추를보고, 결코 떠나지 않는다.

너무 많은 업데이트를 사용하는 것이 맞습니다. 또는 update_idletask에 대한 호출이 dimensionner에 필요하지 않아야합니다.이 함수는 이벤트의 결과로만 호출되므로 함수가 호출 될 때 UI가 이미 최신 상태 여야합니다.

또한 코드 작성자는 생각하는대로 수행하지 않는 많은 코드가 있습니다. 예를 들어 :

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

에만 버튼 내부 을 배치 버튼의 아이들에 영향을 미칠 것입니다. 귀하의 코드는 단추 내부에 위젯을 넣지 않습니다 (매우 특이합니다). grid_rowconfiguregrid_columnconfigure을 호출하면 행과 열 내부에이 포함 된 위젯의 행 및 열이 아닌 위젯을 구성합니다.

+0

버튼이 당신에 의해 사라지지 않는 것은 이상합니다 ... 다른 컴퓨터에서 그것을 복제 해 볼 수 있는지 알아볼 것입니다. self.bl은 단추가 아니라 배경 레이블입니다. 이 위젯에는 버튼이 있습니다. 그래서 여기에 row_columnconfigure를 사용했습니다. dimensionner의 업데이트 내용을 알지 못해서 정보를 제공해 주셔서 감사합니다. – Aegim

관련 문제