2016-07-16 4 views
0

2つのpythonファイルがあります。最初のファイルにはmainWindowが含まれ、2番目のpythonファイルには別のウィンドウが含まれています。私は2番目のウィンドウを表示させることができますが、ウィンドウは表示された後は空白です。ここにエラーのスクリーンショットがあります。 enter image description hereメインウィンドウでボタンをクリックすると、2番目のウィンドウが空白になります

ここでは、[設定]ボタンをクリックした後に表示される内容を示します。メインウィンドウのファイルで enter image description here

、私はこのようなコードを定義します。

from tkinter import * 
import configureUAHChange as cA 

class TracingInterface(Frame): 
    def __init__(self, master): 
     super().__init__() 
     root.minsize(width=700, height=520) 
     root.maxsize(width=700, height=520) 
     Frame.__init__(self, master) 
     Grid.config(self) 
     self.TracingMethod() 
     self.logDetails() 
     self.otherFunctionInterface() 
     # Default window state 
     self._configureUA_window = None 

    def UAconfig_window(self): 
     if self._configureUA_window is not None: 
      return 
     self._configureUA_window =cA.ConfigureUAinterface(self) 

    def closeUA(self): 
     # Destroy the 2nd and reset the value to None 
     if self._configureUA_window is not None: 
      self._configureUA_window.destroy() 
      self._configureUA_window = None 

この行は、ボタンのクリックコマンドのためである:これは、私は関数を定義する方法である、

self.configUAButton = Button(self.radioframe, text="Configuration",command=self.UAconfig_window) 

次第2のpythonファイル

class ConfigureUAinterface(Toplevel): 
def __init__(self, master): 
    super().__init__(master) 
    master.minsize(width=700, height=520) 
    master.maxsize(width=700, height=520) 

    Frame.__init__(self, master) 
    Grid.config(self) 

    master.title("UA Configuration") 

    #Pre define combobox value in case suggestion 
    self.value_of_combo='Identity Theft' 

    #Run the all Function 
    self.DateSelection() 
    self.finish() 
    self.UASuggestion() 
    self.ConfigurationUA() 
    self.suggestionCombo() 

私はどのように上記のエラーを解決するために自分のコードを変更することができます。

これは、メインウィンドウのための完全なコードです:https://drive.google.com/open?id=1KKgYPbGMNNWBfPVazHfcM_NSFlv5eEpKg3_uXsvQsNE

は、これにより、第2のウィンドウのための完全なコードです:https://drive.google.com/open?id=1LuqJXIUrDMLfuz8gnZynZXUN6-SvFAyw9c-puJ3REPQ

答えて

1

1)私はTracingInterface__init__機能にmasterすべきことであるが、いくつかのrootがあると思います。あなたはConfigureUAinterfaceに渡す

2)マスターは、フレームであるとminsizemaxsizetitleメソッドを持っていないウィンドウが、TracingInterfaceではありません。

3)Frame.__init__(self, master)を使用する理由はわかりませんが、ConfigureUAinterfaceToplevelから継承しています。

編集:第二のウィンドウのための

class TracingInterface(Frame): 
    def __init__(self, master): 
     super().__init__() 

     # 1) master instead of root (it was just a typo I think) 
     master.minsize(width=700, height=520) 
     master.maxsize(width=700, height=520) 
     # Frame.__init__(self, master): redundant with super().__init__() 
     Grid.config(self) 
     self.TracingMethod() 
     self.logDetails() 
     self.otherFunctionInterface() 
     # Default window state 
     self._configureUA_window = None 

    def UAconfig_window(self): 
     if self._configureUA_window is not None: 
      return None 
     # 2) changed self which is a frame to the actual window self.master 
     self._configureUA_window = cA.ConfigureUAinterface(self.master) 

変更::私は、コードで何かを変更しなかったし、私が試したとき、それが働いた

class ConfigureUAinterface(Toplevel): 
    def __init__(self, master): 
     super().__init__(master) 
     # replaced master by self since it's the Toplevel size we want to limit 
     self.minsize(width=700, height=520) 
     self.maxsize(width=700, height=520) 

     # 3) The following is inapropriate since the widget 
     # inherit from Toplevel, not Frame: 
     # Frame.__init__(self, master) 
     # Grid.config(self) 

     # replaced master by self since it's the Toplevel title 
     self.title("UA Configuration") 

     #Pre define combobox value in case suggestion 
     self.value_of_combo='Identity Theft' 

     #Run the all Function 
     self.DateSelection() 
     self.finish() 
     self.UASuggestion() 
     self.ConfigurationUA() 
     self.suggestionCombo() 

メインウィンドウの 変更。

+0

もし私がコーディングを変更したいのであれば、私はあなたの提案でそれを修正することができます、よろしく –

関連する問題