How deal with this?help

hello,what is wrong with this following code?who know?

import wx

class MyFrame(wx.Frame):
def init(self):
super().init(None, title=“文本输入控件”, size=(300, 260))
panel = wx.Panel(parent=self)
self.statictext=wx.StaticText(parent=panel,label=“请单击OK按钮”,pos=(110,20))
tc1 = wx.TextCtrl(panel)
b=wx.Button(parent=panel,label=‘OK’)
self.Bind(wx.EVT_BUTTON, self.on_click, b)

    userid = wx.StaticText(panel, label="用户ID:")
 

    # 创建垂直方向的盒子布局管理器对象vbox
    vbox = wx.BoxSizer(wx.VERTICAL)

    # 添加控件到vbox布局管理器
    vbox.Add(userid, flag=wx.EXPAND|wx.LEFT, border=10)
    vbox.Add(tc1, flag=wx.EXPAND|wx.ALL, border=10)
    vbox.Add(b, flag=wx.EXPAND|wx.LEFT, border=10)
    vbox.Add(self.statictext, flag=wx.EXPAND|wx.ALL, border=10)

    # 设置面板(panel)采用vbox布局管理器
    panel.SetSizer(vbox)

    # 设置tc1初始值
    tc1.SetValue('tony')
    # 获取tc1值
    print('读取用户ID:{0}'.format(tc1.GetValue()))
    

def on_click(self,event):

     self.statictext.SetLabelText(tc1.SetValue())

app = wx.App()
frm = MyFrame()
frm.Show()
app.MainLoop()

Hi @GOODLUCK

It would make it easier to help if you were to include you code as either pre-formatted text or uploaded as an attached file, so as to preserve the indentation, etc…

However, I have tried to fix the problems:

import wx

class MyFrame(wx.Frame):

    def __init__(self):
        super().__init__(None, title="文本输入控件", size=(300, 260))
        panel = wx.Panel(parent=self)
        self.statictext = wx.StaticText(parent=panel,label="请单击OK按钮",pos=(110,20))
        self.tc1 = wx.TextCtrl(panel)
        b = wx.Button(parent=panel,label='OK')
        self.Bind(wx.EVT_BUTTON, self.on_click, b)

        userid = wx.StaticText(panel, label="用户ID:")


        # 创建垂直方向的盒子布局管理器对象vbox
        vbox = wx.BoxSizer(wx.VERTICAL)

        # 添加控件到vbox布局管理器
        vbox.Add(userid, flag=wx.EXPAND|wx.LEFT, border=10)
        vbox.Add(self.tc1, flag=wx.EXPAND|wx.ALL, border=10)
        vbox.Add(b, flag=wx.EXPAND|wx.LEFT, border=10)
        vbox.Add(self.statictext, flag=wx.EXPAND|wx.ALL, border=10)

        # 设置面板(panel)采用vbox布局管理器
        panel.SetSizer(vbox)

        # 设置tc1初始值
        self.tc1.SetValue('tony')
        # 获取tc1值
        print('读取用户ID:{0}'.format(self.tc1.GetValue()))
    

    def on_click(self, event):

        self.statictext.SetLabelText(self.tc1.GetValue())


app = wx.App()
frm = MyFrame()
frm.Show()
app.MainLoop()

  1. The first method in the MyFrame class should be __init__(), not init() i.e. with double underscore characters prefix and suffix.

  2. All double and single quote characters should be the standard ascii versions.

  3. The wx.TextCtrl variable tc1 should be an attribute of MyFrame i.e. self.tc1 so that it can be accessed in both methods.

  4. In the on_click() method you need to call self.tc1.GetValue(), not tc1.SetValue().

THANK YOU VERY MUCH!
The program runs well.