Solved

error while populating wx.textCtrl

Posted on 2010-11-26
2
613 Views
Last Modified: 2012-08-13
im trying to populate wx.Textctrl , multiline
(self.name_of1 = wx.TextCtrl(panel, -1,self.staff1,pos=(30,30),size=(500,500),style = wx.TE_MULTILINE)
from a file a text file.... this is the error im getting and the code im running

'clay', 'riley', 'nicole', 'fartgameone', 'two', 'three', 'forgut', 'food', 'hobo', 'thunder', 'dog']
['clay', 'riley', 'nicole', 'fartgameone', 'two', 'three', 'forgut', 'food', 'hobo', 'thunder', 'dog', 'dod']
['clay', 'riley', 'nicole', 'fartgameone', 'two', 'three', 'forgut', 'food', 'hobo', 'thunder', 'dog', 'dod', 'fut']
['clay', 'riley', 'nicole', 'fartgameone', 'two', 'three', 'forgut', 'food', 'hobo', 'thunder', 'dog', 'dod', 'fut', 'kkfkjkfj']
['clay', 'riley', 'nicole', 'fartgameone', 'two', 'three', 'forgut', 'food', 'hobo', 'thunder', 'dog', 'dod', 'fut', 'kkfkjkfj', 'kkfkjkfj']
Traceback (most recent call last):
  File "C:\Python26\sign\turkeydayversionnov27.py", line 987, in staffing
    self.name_of1 = wx.TextCtrl(panel, -1,self.staff1,pos=(30,30),size=(500,500),style = wx.TE_MULTILINE)
  File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py", line 1736, in __init__
    _controls_.TextCtrl_swiginit(self,_controls_.new_TextCtrl(*args, **kwargs))
TypeError: String or Unicode type required

 def staffing(self,event):
        frameV = wx.Frame(None, -1,
                         "Staffing",
                         pos=(50,50), size=(720,720),
                         style=wx.DEFAULT_FRAME_STYLE)
        panel=wx.Panel(frameV)
        self.population(self)
        certlist=['Basic','Intermediate','Paramedic']
       
        wx.StaticText(panel, -1, 'Name of Provider',(30,0))
        self.name_of1 = wx.TextCtrl(panel, -1,self.staff1,pos=(30,30),size=(500,500),style = wx.TE_MULTILINE)
        #-------------------buttons---------------------------------------
        self.btnsave = wx.Button(panel, -1, "&Save", (30,630))
        self.btnsave.Bind(wx.EVT_BUTTON, self.personelstaff, self.btnsave)        
        self.btnupdate = wx.Button(panel, -1, "&Update", (120,630))
        self.btnupdate.Bind(wx.EVT_BUTTON, self.updatepersonelstaff, self.btnupdate)
        #-------------------------------------------------------------------------
        self.frameV = frameV      
        self.frameV.Show()
    def personelstaff(self,event):
        
        dlg = wx.MessageDialog(self, "Caution", caption = "If you have data already saved it will be lost" , style = wx.OK | wx.ICON_EXCLAMATION)
        dlg.ShowModal()
        dlg == wx.OK
        dlg.Destroy()
        self.personelstaffcontinue(self)
        
    def personelstaffcontinue(self,event):              
         
        fileD= open("staffer.txt","w")
        fileD.write("%s\n" %self.name_of1.GetValue())
        self.personel(self)
    def population(self,event):
        try:
            staff=[]
            staffing=open("staffer.txt")
            for line in staffing:
                staff.append(line.rstrip())
                self.staff1=staff 
                print self.staff1
                
            return staff
        except NameError:
            pass 
        
    def updatepersonelstaff(self,event):
         
        fileD= open("staffer.txt","a")
        fileD.write("%s\n" %self.name_of1.GetValue())
        fileD.close()
        self.repopulate(self)
        self.frameV.Destroy
    def supplies(self,event):

Open in new window

0
Comment
Question by:dolamitejenkins
2 Comments
 
LVL 3

Accepted Solution

by:
Mytix earned 500 total points
Comment Utility
the code in :
self.name_of1 = wx.TextCtrl(panel, -1,self.staff1,pos=(30,30),size=(500,500),style = wx.TE_MULTILINE)
should look something like:
self.name_of1 = wx.TextCtrl(panel, -1," ".join(self.staff1),pos=(30,30),size=(500,500),style = wx.TE_MULTILINE)
the reason is that self.staff1 is a list but it should be a string when you're trying to use it in the wx.TextCtrl.
Hope that makes sense
0
 

Author Closing Comment

by:dolamitejenkins
Comment Utility
solved
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now