English 中文(简体)
如何操作代码,只能点击ton子。
原标题:How to run code only when i click on a button..python/wxpython/boa constructor

I m developing a GUI using wxPython (Boa Constructor IDE). My GUI has the following:

  1. Rich text control
  2. Start button
  3. Stop Button

我的要求是,当我发布《裁武条约》季刊时,数字(1、2、3等)应开始在文字控制中印刷;当我发布《STOP》季刊时,应停止印刷。 《刑法》和《两性平等法》都显示了这一点。 为满足我的要求,我需要作哪些改动?

<><>Appearance:

enter image description here

http://www.ohchr.org。

import wx
import wx.richtext

def create(parent):
    return Frame3(parent)

[wxID_FRAME3, wxID_FRAME3BUTTON1, wxID_FRAME3BUTTON2, wxID_FRAME3PANEL1, 
 wxID_FRAME3RICHTEXTCTRL1, 
] = [wx.NewId() for _init_ctrls in range(5)]

class Frame3(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don t edit
        wx.Frame.__init__(self, id=wxID_FRAME3, name=  , parent=prnt,
              pos=wx.Point(579, 234), size=wx.Size(414, 492),
              style=wx.DEFAULT_FRAME_STYLE, title= Frame3 )
        self.SetClientSize(wx.Size(406, 458))

        self.panel1 = wx.Panel(id=wxID_FRAME3PANEL1, name= panel1 , parent=self,
              pos=wx.Point(0, 0), size=wx.Size(406, 458),
              style=wx.TAB_TRAVERSAL)

        self.richTextCtrl1 = wx.richtext.RichTextCtrl(id=wxID_FRAME3RICHTEXTCTRL1,
              parent=self.panel1, pos=wx.Point(96, 96), size=wx.Size(200, 100),
              style=wx.richtext.RE_MULTILINE, value=u  )
        self.richTextCtrl1.SetLabel(u richText )

        self.button2 = wx.Button(id=wxID_FRAME3BUTTON2, label=u STOP ,
              name= button2 , parent=self.panel1, pos=wx.Point(256, 280),
              size=wx.Size(75, 23), style=0)
        self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
              id=wxID_FRAME3BUTTON2)

        self.button1 = wx.Button(id=wxID_FRAME3BUTTON1, label=u START ,
              name= button1 , parent=self.panel1, pos=wx.Point(88, 280),
              size=wx.Size(75, 23), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_FRAME3BUTTON1)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnButton1Button(self, event):  #START BUTTON
        event.Skip()

    def OnButton2Button(self, event):  #STOP BUTTON
        event.Skip()


if __name__ ==  __main__ :
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()
最佳回答

Summary

总的来说,这是在WxPython这样做的一种公认方式,直接来自。 页: 1

  1. 创建新的“数据”活动。

  2. 让你的控制者聆听“数据”活动

  3. Let pressing the "Start" button start a thread that increments a counter and sends a "data" event to your window with the counter value attached.

  4. 收到这项活动后,将贵条码增值。 RichTextCtrl

Example

这里就是一个例子。 特别注意到<代码>Connect()用于聆听即将举办的价值活动。

import wx
import wx.richtext
import threading
import time


EVT_ID_VALUE = wx.NewId()

class DataEvent(wx.PyEvent):
  def __init__(self, data):
    wx.PyEvent.__init__(self)
    self.SetEventType(EVT_ID_VALUE)
    self.data=data


class Frame3(wx.Frame):
  def __init__(self, parent, title):
    self.counter = 0
    self.worker = None

    wx.Frame.__init__(
      self, name=  , 
      parent=parent,
      pos=wx.Point(579, 234), 
      size=wx.Size(414, 492),
      style=wx.DEFAULT_FRAME_STYLE, title= Frame3 
    )
    self.panel1 = wx.Panel(
      name= panel1 , 
      parent=self,
      pos=wx.Point(0, 0), 
      size=wx.Size(406, 458),
      style=wx.TAB_TRAVERSAL
    )
    self.richTextCtrl1 = wx.richtext.RichTextCtrl(
      parent=self.panel1, 
      pos=wx.Point(96, 96), 
      size=wx.Size(200, 100),
      style=wx.richtext.RE_MULTILINE, 
      value=u  
    )
    self.richTextCtrl1.SetLabel(u richText )
    self.richTextCtrl1.SetScrollbars(20,20,50,50)
    self.button2 = wx.Button(
      label=u STOP ,
      name= button2 , 
      parent=self.panel1, 
      pos=wx.Point(256, 280),
      size=wx.Size(75, 23), 
      style=0
    )
    self.button2.Bind(
      wx.EVT_BUTTON, 
      self.OnStop
    )
    self.button1 = wx.Button(
      label=u START ,
      name= button1 , 
      parent=self.panel1, 
      pos=wx.Point(88, 280),
      size=wx.Size(75, 23), 
      style=0
    )
    self.button1.Bind(
      wx.EVT_BUTTON, 
      self.OnStart
    )
    self.Connect(-1, -1, EVT_ID_VALUE, self.OnValue )

  def OnValue(self, event):
    self.richTextCtrl1.AppendText("%d
"%event.data)
    
  
  def OnStart(self, event):  #START BUTTON
    self.richTextCtrl1.AppendText("START
")
    if not self.worker:
      self.worker = WorkerThread(self)
      self.worker.start() 

  def OnStop(self, event):  #STOP BUTTON
    self.richTextCtrl1.AppendText("STOP
")
    if self.worker:
      self.worker.stop() 


class WorkerThread(threading.Thread):
  def __init__(self, notify_window):
    threading.Thread.__init__(self)
    self.counter = 0
    self._notify_window = notify_window
    self.abort = False 

  def run(self):
    while not self.abort:
      self.counter += 1
      wx.PostEvent(self._notify_window, DataEvent(self.counter))
      time.sleep(1)

  def stop(self):
      self.abort = True



if __name__ ==  __main__ :
    app = wx.App()
    frame = Frame3(None, "My Hello App")
    frame.Show(True)
    app.MainLoop()
问题回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签