문제

I have created my GUI using wxGlade and it looks fine in the display. I am now trying to run the code it generated before adding it to my finished Python program. I have tryed copying it in to the file structure and running it then copying the code into a new file. I have check the files needed are on the pythonpath and they are all. Everytime I get this same error message. Error message

Traceback (most recent call last):
  File "C:\Users\Steb\workspace\Check\GuiAttempt.py", line 85, in <module>
    frame_4 = FirstScreen(None, -1, "")
  File "C:\Users\Steb\workspace\Check\GuiAttempt.py", line 21, in __init__
    self.Title = wxPanel(self, -1, style=wxDOUBLE_BORDER|wxTAB_TRAVERSAL)
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py", line 402, in SetTitle
    return _windows_.TopLevelWindow_SetTitle(*args, **kwargs)
TypeError: String or Unicode type required

code

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.5 (standalone edition) on Wed Mar 28 19:14:57 2012

from wxPython.wx import *

# begin wxGlade: extracode
# end wxGlade


class FirstScreen(wxFrame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: FirstScreen.__init__
        kwds["style"] = wxDEFAULT_FRAME_STYLE
        wxFrame.__init__(self, *args, **kwds)
        self.Title = wxPanel(self, -1, style=wxDOUBLE_BORDER|wxTAB_TRAVERSAL)
        self.label_1 = wxStaticText(self.Title, -1, "LA Task Refactoriser\n", style=wxALIGN_CENTRE)
        self.tree_ctrl_2 = wxTreeCtrl(self, -1, style=wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT|wxTR_DEFAULT_STYLE|wxSUNKEN_BORDER)
        self.sizer_9_staticbox = wxStaticBox(self, -1, "File A")
        self.tree_ctrl_3 = wxTreeCtrl(self, -1, style=wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT|wxTR_DEFAULT_STYLE|wxSUNKEN_BORDER)
        self.sizer_10_staticbox = wxStaticBox(self, -1, "File B")
        self.tree_ctrl_4 = wxTreeCtrl(self, -1, style=wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT|wxTR_DEFAULT_STYLE|wxSUNKEN_BORDER)
        self.sizer_11_staticbox = wxStaticBox(self, -1, "File C")
        self.button_1 = wxButton(self, -1, "Load Files")
        self.button_2 = wxButton(self, -1, "Quit")

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: FirstScreen.__set_properties
        self.SetTitle("frame_4")
        self.SetSize((387, 417))
        self.SetBackgroundColour(wxColour(255, 255, 255))
        self.label_1.SetMinSize((160, 38))
        self.label_1.SetBackgroundColour(wxColour(255, 255, 255))
        self.label_1.SetFont(wxFont(12, wxROMAN, wxNORMAL, wxBOLD, 0, ""))
        self.label_1.Enable(False)
        self.Title.SetBackgroundColour(wxColour(255, 255, 255))
        self.Title.SetForegroundColour(wxColour(0, 0, 255))
        self.Title.SetFont(wxFont(12, wxSCRIPT, wxNORMAL, wxBOLD, 0, ""))
        self.Title.Enable(False)
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: FirstScreen.__do_layout
        sizer_6 = wxBoxSizer(wxVERTICAL)
        sizer_7 = wxBoxSizer(wxVERTICAL)
        sizer_12 = wxBoxSizer(wxHORIZONTAL)
        self.sizer_11_staticbox.Lower()
        sizer_11 = wxStaticBoxSizer(self.sizer_11_staticbox, wxHORIZONTAL)
        self.sizer_10_staticbox.Lower()
        sizer_10 = wxStaticBoxSizer(self.sizer_10_staticbox, wxHORIZONTAL)
        self.sizer_9_staticbox.Lower()
        sizer_9 = wxStaticBoxSizer(self.sizer_9_staticbox, wxHORIZONTAL)
        sizer_8 = wxBoxSizer(wxHORIZONTAL)
        sizer_8.Add(self.label_1, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 100)
        self.Title.SetSizer(sizer_8)
        sizer_7.Add(self.Title, 2, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5)
        sizer_9.Add(self.tree_ctrl_2, 1, wxEXPAND, 0)
        sizer_7.Add(sizer_9, 1, wxEXPAND, 0)
        sizer_10.Add(self.tree_ctrl_3, 1, wxEXPAND, 0)
        sizer_7.Add(sizer_10, 1, wxEXPAND, 0)
        sizer_11.Add(self.tree_ctrl_4, 1, wxEXPAND, 0)
        sizer_7.Add(sizer_11, 1, wxEXPAND, 0)
        sizer_12.Add(self.button_1, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 75)
        sizer_12.Add(self.button_2, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 75)
        sizer_7.Add(sizer_12, 1, wxEXPAND, 0)
        sizer_6.Add(sizer_7, 1, wxEXPAND, 0)
        self.SetSizer(sizer_6)
        self.Layout()
        self.SetSize((387, 417))
        # end wxGlade

# end of class FirstScreen
if __name__ == "__main__":
    app = wxPySimpleApp(0)
    wxInitAllImageHandlers()
    frame_4 = FirstScreen(None, -1, "")
    app.SetTopWindow(frame_4)
    frame_4.Show()
    app.MainLoop()

I am using Python 2.7, my IDE is eclipse indigo with PyDev. Please help.

도움이 되었습니까?

해결책

Your problem is with this:

self.Title = wxPanel(self, -1, style=wxDOUBLE_BORDER|wxTAB_TRAVERSAL)

You have named a panel Title, but Title is a propery that expects a string or unicode.

If you rename Title to something else (like MyTitle), your code will work.

Do a Find > Replace in your favorite editor and change all instances of self.Title to self.MyTitlePanel (for example) save the file and run it again.

다른 팁

You named one of your inner panels (children of FirstScreen) Title, so wxGlade tries to assign it to a variable self.Title. Incidentally, self.Title is a property of wxFrame that is used to set the title of the frame, and expects a string as its argument.

To avoid such name clashes, you can prefix your instance variable names with underscores.

I recommend changing to the superb wxFormBuilder.

With wxGlade I messed around for an hour getting nowhere. Today I tried wxFormBuilder, and had a good working wxPython GUI in less than 30 minutes, complete with events, text boxes, buttons, etc.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top