2013-08-18 49 views
2

我正在寫一個GUI,我想我的主界面屏幕前做一個登錄界面,但我不能找出正確的方式做到這一點wxPython的登錄功能

開始我嘗試構建它像這樣:

class GUI(wx.Frame): 
    #GUI 
    def __init__(self, parent, id, title): 
     state = 1 
     if state ==1: 
      #Login screen code 
     elif state == 2: 
      #Main Screen code 

但沒有工作沒有彈出

所以我試圖創建一個主窗口前彈出一個完全不同的小窗口,但不能得到那個工作

所以我的問題是我怎樣才能讓我的GUI的登錄屏幕正確

謝謝你!

+0

'__init__'只運行一次,因爲每次啓動'GUI'國家將'1'不管'GUI'將始終顯示相同的內容。向我們展示更多的代碼,當你創建你的類時更符合邏輯。例如,如果你重新使用這個類,使'state'成爲一個參數。也許把'狀態#2'放在一個函數或其他東西中? – Torxed

+0

它在登錄屏幕上按OK按鈕時變爲狀態2,但它甚至沒有顯示登錄屏幕 – Serial

+0

如何實例化'GUI',甚至在任何地方調用'wx.Frame .__ init__'? 請您發佈完整的代碼,因爲這段代碼對我們來說毫無用處(沒有冒犯,但它太模糊)。這就像是說「我與我的熱狗有問題」,而我們不知道你是素食主義者還是有熱狗。或者,如果你只是想念你的熱狗包:/ – Torxed

回答

0

的東西在這裏就是我打開一推出首選項窗口爲GooeyPi:我PyInstaller GUI前端。這可以很容易地適應有一個密碼對話框或框架。我分成兩個功能:檢查用戶是否有設置偏好,並打開偏好窗口。這允許他們稍後改變偏好。我使用ShowModal來防止用戶在設置之前使用該應用程序。

class GooeyPi(wx.Frame): 
    def __init__(self, *args, **kwargs): 
     super(GooeyPi, self).__init__(*args, **kwargs) 
     self.InitUI() 
     self.SetSize((460,350)) 
     self.SetTitle('GooeyPi - PyInstaller GUI') 
     self.Show() 
     self.CheckFirstRun() # Checks for first run here. 

    ..... 

    def CheckFirstRun(self): 
     config = controller.getConfig() 
     if config['pyidir'] == '': 
      ... 
      self.OnPreferences(None) 
    .... 

    def OnPreferences(self, e): 
     prefdlg = pref.Preferences(None, title='Edit Preferneces') 
     prefdlg.ShowModal() 
     prefdlg.Destroy() 

和pref.Preferences是definied在一個單獨的模塊:

class Preferences(wx.Dialog): 
    def __init__(self, *args, **kw): 
     super(Preferences, self).__init__(*args, **kw) 
     self.InitUI() 
     self.SetSize((380,290)) 
     self.SetTitle("Preferences") 

    def InitUI(self): 
     you_get_the_idea... 
+0

這是有幫助的,我做的是創建登錄並顯示它首先然後主窗口被稱爲按鈕推事件謝謝你雖然生病接受你的回答:) – Serial

+0

另一個好方法! – pedram

0

我推薦使用內置的wx.PasswordEntryDialog,並根據密碼對話框中的條目顯示或隱藏主窗口。你甚至可以把wx.PasswordEntryDialog放在while循環中。像(未經測試)

self.Hide() 
password = "a passphrase" 
entered_password = None 
while entered_password != password: 
    dialog = wx.PasswordEntryDialog(self, "Enter the password", "Please enter the password") 
    ret_value = dialog.ShowModal() 
    if ret_value == wx.ID_OK: 
     entered_password = dialog.GetValue() 
    else: 
     self.Close(True) 
    dialog.Destroy() 
# self.Show()