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