ThePotter
ThePotter

Reputation: 3

wxPython, Getting input from TextCtrl box to send to Notepad

I am trying to create a simple invoice program for a school project. I have the basic layout of my program. The large text boxes on the left are for the invoice, and the ones on the right are for the price of that input.

I want the text boxes to return the input into them, and assign it to say JobOne. The next step is that I need these values to be send to a file in Notepad when the 'Send To Invoice' button is clicked. I am really stuck here, I've tried so many different combinations of things, and I'm forever getting "TextCtrl" object is not callable. Any help would be greatly appreciated. I've taken out my messy attempts to get the problem working and stripped it down to its barebones.

    import wx

class windowClass(wx.Frame):

def __init__(self, *args, **kwargs):
    super(windowClass, self).__init__(*args, **kwargs)

    self.basicGUI()

def basicGUI(self):

    panel = wx.Panel(self)   
    self.SetSizeWH(1200, 800)
    menuBar = wx.MenuBar()
    fileButton = wx.Menu()
    exitItem = fileButton.Append(wx.ID_EXIT, 'Exit', 'status msg...')
    menuBar.Append(fileButton, 'File')
    self.SetMenuBar(menuBar)
    self.Bind(wx.EVT_MENU, self.Quit, exitItem)





    yesNoBox = wx.MessageDialog(None, 'Do you wish to create a new invoice?',
                                'Create New Invoice?', wx.YES_NO)
    yesNoAnswer = yesNoBox.ShowModal()
    yesNoBox.Destroy()



    nameBox = wx.TextEntryDialog(None, 'What is the name of the customer?', 'Customer Name'
                                 , 'Customer Name')

    if nameBox.ShowModal() ==wx.ID_OK:
        CustomerName = nameBox.GetValue()



   wx.TextCtrl(panel, pos=(10, 10), size=(500,100))



    wx.TextCtrl(panel, pos=(550, 10), size=(60,20))




    wx.TextCtrl(panel, pos=(10, 200), size=(500,100))

    wx.TextCtrl(panel, pos=(550, 200), size=(60,20))





    wx.TextCtrl(panel, pos=(10, 400), size=(500,100))


    wx.TextCtrl(panel, pos=(550, 400), size=(60,20))



    self.SetTitle('Invoice For ' +CustomerName)  


    SendToNotepadButton = wx.Button(panel, label='Convert to invoice',pos=(650, 600), size=(120, 80))
    def SendToNotepad(e):
        f = open("Notepad.exe", 'w')
        f.write(())
        call(["Notepad.exe", "CustomerInvoice"])



    self.Bind(wx.EVT_BUTTON, SendToNotepad)                                                                                           
    self.Show(True)



def Quit(self, e):
    self.Close()


def main():
app = wx.App()
windowClass(None)

app.MainLoop()

main()

If you manage to help me, I thank you!

Upvotes: 0

Views: 447

Answers (1)

Mike Driscoll
Mike Driscoll

Reputation: 33071

This is actually fairly easy. I skipped the MessageDialog stuff and just put together a proof of concept. This worked for me on my Windows 7 box with Python 2.7 and wxPython 3.0.2:

import subprocess
import wx

########################################################################
class MyPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        self.txt = wx.TextCtrl(self)
        notepad_btn = wx.Button(self, label="Send to Invoice")
        notepad_btn.Bind(wx.EVT_BUTTON, self.onSendInvoice)

        my_sizer = wx.BoxSizer(wx.VERTICAL)
        my_sizer.Add(self.txt, 0, wx.EXPAND|wx.ALL, 5)
        my_sizer.Add(notepad_btn, 0, wx.CENTER|wx.ALL, 5)
        self.SetSizer(my_sizer)

    #----------------------------------------------------------------------
    def onSendInvoice(self, event):
        """"""
        txt = self.txt.GetValue()
        print txt

        # write to file
        with open("invoice.txt", 'w') as fobj:
            fobj.write(txt)

        # open Notepad
        subprocess.Popen(['notepad.exe', 'invoice.txt'])


########################################################################
class MainWindow(wx.Frame):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="Jobs")
        panel = MyPanel(self)
        self.Show()

if __name__ == '__main__':
    app = wx.App(False)
    frame = MainWindow()
    app.MainLoop()

Hopefully this code will help you see how to put it all together.

Upvotes: 1

Related Questions