2013-10-01 82 views
0

這是我編輯並嘗試工作,但仍然無法正常工作的當前代碼:/調試幫助將是真棒:)它給變量「自我」和「父母」沒有被定義在mainWindow類,以及與「class mainWindow」類錯誤。不完全知道什麼他們都意味着什麼或如何修正tkinter類聲明和全局名稱「父母」未定義的GUI錯誤?

import sys, Tkinter 
sys.modules['tkinter'] = Tkinter 
import Pmw 

class Print: 

    def __init__(self, text): 
     self.text = text 

    def __call__(self): 
     print self.text 

class mainWindow: 

    def __init__(self,parent,balloon): 
     self.balloon = Pmw.Balloon(parent) 
     self.parent = parent 
     self.menuBar = menuBar 
     self.mainPart = mainPart 
     self.buttonBox = buttonBox 

    def Quit(): 
     root.destroy() 

    menuBar = Pmw.MenuBar(parent,hull_relief = 'raised',hull_borderwidth = 1,balloon = self.balloon) 
    menuBar.pack(fill = 'x') 

    menuBar.addmenu('Run Control','Calibration,Download Configuration,Number of Triggers,Data Output File,Upload Configuration,Start DAQ,Quit') 
    menuBar.addcascademenu('Run Control','Calibration','View and/or change the calibration',traverseSpec = 'z',tearoff = 1) 
    menuBar.addmenuitem('Calibration','command','Display the DAC calibration',command = Print('display the DAC calibration'),label = 'Display DAC Calibration') 

    menuBar.addmenuitem('Calibration','command','Display the calibration mask',command = Print('display the calibration mask'),label = 'Display Calibration Mask') 
    menuBar.addmenuitem('Calibration','command','Change the DAC calibration',command = Print('change the DAC calibration'),label = 'Change DAC Calibration') 
    menuBar.addmenuitem('Calibration','command','Change the calibration mask',command = Print('change the calibration mask'),label = 'Change Calibration Mask') 

    menuBar.addmenuitem('Run Control','command','Download a configuration',command = Print('download configuration'),label = 'Download Configuration') 

    menuBar.addmenuitem('Run Control','command','Set the number of triggers',command = Print('set number of triggers'),label = 'Number of Triggers') 
    menuBar.addmenuitem('Run Control','command','Change the file where the data will be sent to',command = Print('set data output file'),label = 'Data Output File') 
    menuBar.addmenuitem('Run Control','command','Upload a configuration',command = Print('upload a configuration'),label = 'Upload Configuration') 

    menuBar.addmenuitem('Run Control','command','Start the data aquisition',command = Print('start data aquisition'),label = 'Start DAQ') 
    menuBar.addmenuitem('Run Control','separator') 
    menuBar.addmenuitem('Run Control','command','Close the GUI',command = Quit,label = 'Quit') 
    menuBar.addmenu('Slow Control','Voltage, Current,Temperature,DAC Settings') 
    menuBar.addmenuitem('Slow Control','command','Display the voltage',command = Print('display voltage'),label = 'Voltage') 
    menuBar.addmenuitem('Slow Control','command','Display the current',command = Print('display current'),label = 'Current') 
    menuBar.addmenuitem('Slow Control','command','Display the temperature',command = Print('display temperature'),label = 'Temperature') 
    menuBar.addmenuitem('Slow Control','command','Display the DAC settings',command = Print('display DAC settings'),label = 'DAC Settings') 
    menuBar.addmenu('Graphics','Channel Map,Energy Detector,Root Output,Slow Control Time,Histograms,One Event Display') 
    menuBar.addmenuitem('Graphics','command','Display the channel map',command = Print('display channel map'),label = 'Channel Map') 
    menuBar.addmenuitem('Graphics','command','Display the energy detector',command = Print('display energy detector'),label = 'Energy Detector') 
    menuBar.addmenuitem('Graphics','command','Display the root output',command = Print('display root output'),label = 'Root Output') 
    menuBar.addmenuitem('Graphics','command','Display the slow control time',command = Print('display slow control time'),label = 'Slow Control Time') 
    menuBar.addmenuitem('Graphics','command','Display various histograms',command = Print('display histograms'),label = 'Histograms') 
    menuBar.addmenuitem('Graphics','command','Display the one event display',command = Print('display one event display'),label = 'One Event Display') 
    menuBar.addmenu('Edit Data Base','Make Configuration Files') 
    menuBar.addmenuitem('Edit Data Base','command','Make the Configuration Files',command = Print('create configuration files'),label = 'Create Configuration Files') 

    mainPart = Tkinter.Label(parent,text = 'GUI',background = 'white',foreground = 'white',padx = 100,pady = 100) 
    mainPart.pack(fill = 'both', expand = 1) 

    buttonBox = Pmw.ButtonBox(parent) 
    buttonBox.pack(fill = 'x') 
    buttonBox.add('Start\nRoot', command = Print('start root')) 

if __name__ == '__main__': 
    root = Tkinter.Tk() 
    Pmw.initialise(root) 
    root.title('pCT GUI') 
    root.mainloop() 
+0

你應該給你的問題的詳細信息(源代碼)錯誤消息。你會得到什麼樣的錯誤信息?要處理縮進問題,請將所有制表符轉換爲空格。在大多數情況下,這解決了所有問題。 (至少你看到他們然後很可能會修復它們。) – Alfe

回答

0

你應該張貼所有代碼和詳細的錯誤信息,所以我可以更好的幫助,但是從你的貼吧看來你的問題:

class foo: 

爲空。所以,你需要它看起來像

class foo: 
    pass 

爲了不出現錯誤。沒有被定義

家長可能是由於這一事實,你從來沒有定義的變量父,所以你可能想沿着線的東西:

parent = Tkinter.Tk() 
+0

是打開一個新的頂層窗口?我把它放在廣告中爲自己做了這個,它使GUI工作,但它現在打開3個窗口......不知道爲什麼。 – Steven

+0

@ user2833744如果您發佈了您的代碼,我可以更好地回答這個問題,但是請確保您定義了一個父代,並且所有框架都以該父代作爲參數進行了初始化。初始化框架作爲其父項的其他窗口小部件。如果您使用導致問題的代碼編輯帖子,我可以爲您進行調試。 –

+0

我用我的完整代碼編輯了上面的代碼,並且寫了我在運行時遇到的錯誤。 – Steven

0

第一個參數爲MenuBar是指定其MenuBar屬於父窗口。你沒有定義它,你會得到一個錯誤。如果MenuBar是一個頂級窗口部件,只需連接它的根:

root = Tk() 
menuBar = Pmw.MenuBar(root, 
    hull_relief = 'raised', 
    hull_borderwidth = 1, 
    balloon = self.balloon) 
menuBar.pack(fill = 'x') 

root.mainloop() 
相關問題