wxPython,从 TextCtrl 框获取输入以发送到记事本

wxPython, Getting input from TextCtrl box to send to Notepad

我正在尝试为学校项目创建一个简单的发票程序。我有我的程序的基本布局。 左边的大文本框是发票,右边的是那个输入的价格。

我希望文本框 return 输入内容,并将其指定为 JobOne。下一步是我需要在单击 'Send To Invoice' 按钮时将这些值发送到记事本中的文件。 我真的被困在这里,我尝试了很多不同的组合,而且我永远得到 "TextCtrl" object is not callable。 任何帮助将不胜感激。 我已采取杂乱无章的尝试来解决问题,并将其简化为准系统。

    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()

如果你能帮到我,我谢谢你!

这其实很简单。我跳过了 MessageDialog 的内容,只是整理了一个概念证明。这适用于我的 Windows 7 盒子 Python 2.7 和 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()

希望这段代码能帮助您了解如何将它们组合在一起。