0
我想从Python中的TextCtrl对象检索文本值,我似乎无法得到它。 该文本在下面的代码中被命名为“text”,我尝试在“Click”函数中检索该值。 我很好理解如何显示文本框和按钮以及如何检索事件,但是当我运行此代码时,我有一个错误,说“myForm”没有属性“文本”,如何设置“文本”为一个属性myForm?如何从文本对象中获取值?如何检索文本从wx python CtrlText?
from datetime import datetime, time
from pygame import mixer # Load the required library
import wx
class myForm(wx.Frame):
def __init__(self, parent, title):
super(myForm, self).__init__(parent,title=title, size=(300, 100))
hbox = wx.BoxSizer(wx.HORIZONTAL)
fgs = wx.FlexGridSizer(3, 2, 9, 25)
panel = wx.Panel(self)
title = wx.StaticText(panel, label="Time in second")
button1 = wx.Button(panel, label="Start")
text=wx.TextCtrl(panel)
self.Bind(wx.EVT_BUTTON, self.Click)
fgs.AddMany([(title), (text, 1, wx.EXPAND),(button1,1,wx.EXPAND)])
fgs.AddGrowableRow(2, 1)
fgs.AddGrowableCol(1, 1)
hbox.Add(fgs, proportion=1, flag=wx.ALL|wx.EXPAND, border=15)
panel.SetSizer(hbox)
self.Centre()
self.Show()
def Click(self, event):
print 'event reached frame class'
#print tc1.GetValue()
print "value",self.text.GetValue()
event.Skip()