2013-10-30 3 views
0

저는 파이썬에 매우 익숙합니다.tkinter 대화 상자를 먼저 표시하는 방법은 무엇입니까?

다음과 같이 코딩했습니다. 사용자가 'CPE를 설정하려면 클릭 버튼'을 클릭합니다. 버튼을 클릭하면 대화 상자 창이 열리고 고객 목록이 표시됩니다.

내 문제는 사용자가 "CPE를 설정하기 위해 클릭 버튼"을 클릭했을 때입니다. 버튼을 누르면 Listing() 기능이 먼저 작동합니다. 그 당시 메인 윈도우는 죽었습니다. Listing()을 완료하면 대화 상자가 나타납니다.

먼저 대화 상자를 표시하고 대화 상자가 나타난 후 정보를 표시하려면 어떻게해야합니까?

import Tkinter 

class myWindow: 
    addr = '' 
    def __init__(self): 

     self.mw = Tkinter.Tk() 
     self.mw.option_add("*font", ("Arial", 15, "normal")) 
     self.mw.geometry("+250+200") 
     self.mw.title("Example of Custom Dialog-Window") 

     # CPE 
     self.btn_cpe = Tkinter.Button(self.mw, text = "Click button to setup CPE.", command = self.btnCPE) 
     self.btn_cpe.pack(padx = 20, pady = 20) 
     self.mw.mainloop() 


    def btnCPE(self): 

     self.dialogwindow = Tkinter.Toplevel() 
     self.dialogwindow.title("Dialog Window") 
     self.dialogwindow.geometry("+500+350") 
     self.dialogwindow.maxsize(500, 350) 
     self.dialogwindow.minsize(500, 350) 

     self.lab1 = Tkinter.Label(self.dialogwindow, text = "Checking info") 
     self.lab1.pack() 

     self.lab_addr = Tkinter.Label(self.dialogwindow, text = "Address : ") 
     self.lab_addr.pack() 

     # Refresh 
     self.btn_refresh = Tkinter.Button(self.dialogwindow, text = "Refresh", command = self.refresh) 
     self.btn_refresh.pack() 

     self.btn_cpe_exit = Tkinter.Button(self.dialogwindow, text = "Exit", command = self.dialogwindow.destroy) 
     self.btn_cpe_exit.pack() 

     # This is the important line: It tells the main-window to lock: 
     self.dialogwindow.grab_set() 

     self.Listing() 
     self.lab_addr['text'] = "address : " + self.addr; 

    def Listing(self): 
     # access the db and set the address into self.addr 

답변

0

이 시도 :

또한
import Tkinter 

class myWindow: 
    addr = '' 
    def __init__(self): 
     # CPE 
     self.btn_cpe = Tkinter.Button(mw, text = "Click button to setup CPE.", command = self.btnCPE) 
     self.btn_cpe.pack(padx = 20, pady = 20) 

    def btnCPE(self): 

     self.dialogwindow = Tkinter.Toplevel() 
     self.dialogwindow.title("Dialog Window") 
     self.dialogwindow.geometry("+500+350") 
     self.dialogwindow.maxsize(500, 350) 
     self.dialogwindow.minsize(500, 350) 

     self.lab1 = Tkinter.Label(self.dialogwindow, text = "Checking info") 
     self.lab1.pack() 

     self.lab_addr = Tkinter.Label(self.dialogwindow, text = "Address : ") 
     self.lab_addr.pack() 

     # Refresh 
     self.btn_refresh = Tkinter.Button(self.dialogwindow, text = "Refresh", command = self.refresh) 
     self.btn_refresh.pack() 

     self.btn_cpe_exit = Tkinter.Button(self.dialogwindow, text = "Exit", command = self.dialogwindow.destroy) 
     self.btn_cpe_exit.pack() 

     # This is the important line: It tells the main-window to lock: 
     self.dialogwindow.grab_set() 

     self.Listing() 
     self.lab_addr['text'] = "address : " + self.addr; 

    def Listing(self): 
     print "hola" 
     # access the db and set the address into self.addr 

mw = Tkinter.Tk() 
app=myWindow() 
mw.option_add("*font", ("Arial", 15, "normal")) 
mw.geometry("+250+200") 
mw.title("Example of Custom Dialog-Window") 
mw.mainloop() 

&는 생성자의 UI 부분을 포함하지 않도록하려고합니다. 도움이되는지 말해주십시오

+0

친구 없음. Pls는 Listing() 함수에서 time.sleep (5)를 추가하고 테스트합니다. –

+0

형, 나는 너에게 그것의 요지를 주었다. 너는 달리기를 원하는대로 ** listing() **은 알아낼 것이다. 잠을 사용하거나 버튼을 사용하여 전화를 걸 수 있습니다. 대화 상자가 먼저 나타나고 나머지는 결정할 것입니다 창을 삭제 한 후 ** Listing() **을 호출 할 수도 있습니다 – Gogo

관련 문제