2016-04-18 7 views
0

私は、あるアプリケーションのすべてのGUIを定義したメインファイルと、アプリケーションにデータをインポートするためのm個のエモッドを持つ別のモジュールを持っています。他のモジュールからTkinterクラスを呼び出す

データをインポートするときに重複したレコードがあるので、メインモジュールに格納されているTkinterクラスを呼び出すことによって、(最初または最後の)レコードを保持するかどうかをユーザーに決定させたいと思います。

Main_App.py

class DialogDupli(tkSimpleDialog.Dialog):#dialog duplicated records 

    def __init__(self, parent): 


     Toplevel.__init__(self, parent) 
     self.transient(parent) 
     title="Delete duplicated records" 
     if title: 
      self.title(title) 
     self.parent = parent 

     self.result = None 
     body = Frame(self) 
     self.initial_focus = self.body(body) 
     body.pack(padx=5, pady=5) 
     self.buttonbox() 
     self.grab_set() 
     if not self.initial_focus: 
      self.initial_focus = self 
     self.protocol("WM_DELETE_WINDOW", self.cancel) 
     self.geometry("+%d+%d" % (parent.winfo_rootx()+50, 
            parent.winfo_rooty()+50)) 
     self.initial_focus.focus_set() 
     self.wait_window(self) 

    def body(self, master): 
     pdb.set_trace() 
     self.selection = StringVar() 

     self.radio=Radiobutton(master, text='Keep First record', variable=self.selection, value='First',state='active').grid(row=0,column=0,sticky=W) 
     self.radio=Radiobutton(master, text='Keep Last record', variable=self.selection, value='Last',state='active').grid(row=1,column=0,sticky=W) 


    def apply(self): 
     cri = self.selection.get() 
     self.result = cri 
root = Tk() 
root.mainloop() 

import.py

from Main_App import DialogDupli 

...私のデータフレームがあった場合、私がチェックし作成され#Onceデータに

をインポートする#かくかくしかじか、その後方法タイムスタンプの重複レコードです

dupli=df.reset_index().duplicated(subset=df.index.names) 
    if dupli.any():#there are duplicates 
     tkMessageBox.showwarning("Duplicated records","There are duplicated records in the Time Stamp") 
     dialog=DialogDupli(root)#here call to the GUI in Main_App.py 

問題は、インポートモジュールが認識されないので、引数のルートを呼び出す方法です。

name 'root' is not defined 

他のウェブサイトでも同様の質問を確認しましたが、まだわかりません。

答えて

3

rootの引数がクラス外で定義されているため、rootのインポートまたは定義を変更する必要があります。

あなたはここに

root = tk.Tk() 
app = DialogDupli(parent=root) 
app.mainloop() 

あなたが持っているあなたのMain_app.pyに貼り付ける必要があります例: https://github.com/piotrowy/steganography_chat/blob/master/client/client.py https://github.com/piotrowy/steganography_chat/blob/master/client/view.py

関連する問題