如何在wxPython中单独编写GUI和事件? [英] How to write GUI and event separately in wxPython??

查看:86
本文介绍了如何在wxPython中单独编写GUI和事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI all


我正在使用wxpython进行申请。

但是当我想更改显示字符串时遇到问题

根据流程状态。


我将框架传递给处理函数并使用

frame.txtobj更改显示字符串。 />

我发现这是一个不好的方法。

任何人都可以告诉我通常怎么做?

(如何分离GUI和控制代码?)


谢谢。

解决方案

On Sun ,2007年7月29日23:34:14 -0700,Jia Lu写道:


我正在使用wxpython进行申请。

但是我当我想根据进程状态更改显示字符串

时出现问题。


我将框架传递给处理函数并使用

frame.txtobj更改显示字符串。


我发现这是一个不好的方法要做到这一点。

任何人都可以告诉我通常怎么做?

(如何分离GUI和控制代码? )



这里的一种可能性是给函数提供一个回调函数

函数,当函数执行它时它会被调用。简单

示例:


def do_work(参数,回调= lambda msg:无):

回调(''开始处理。'')

%xrange(0,101):

回调(''完成%d %% ...''%%)

回调(''完成''')


Ciao,

Marc''BlackJack''Rintsch


Marc''BlackJack''Rintsch写道:


On Sun,2007年7月29日23:34:14 -0700,Jia Lu写道:


>我正在使用wxpython进行应用程序。
但是当我想根据进程状态更改显示字符串时我遇到了问题。

我将框架传递给处理函数并使用
frame.txtobj来更改显示字符串。

我发现这是一个不好的方法。
任何人都可以告诉我通常怎么做?
(如何分离GUI和控制代码?)



这里的一种可能性是给工人一个回调函数

函数当函数执行它时会被调用。简单

示例:


def do_work(参数,回调= lambda msg:无):

回调(''开始处理。'')

%xrange(0,101):

回调(''完成%d %% ...''%%)

回调(''完成。'')


>> [x for x in xrange(0 ,101)] == [y for x in xrange(101)]



True


>>>



问候

Steve

-

Steve Holden +1 571 484 6266 +1 800 494 3119

Holden Web LLC / Ltd http://www.holdenweb.com

Skype:holdenweb http://del.icio.us/steve.holden

--------------- Asciimercial - ----------------

上网:博客,镜头和互联网标签

许多服务目前提供免费注册

-----------感谢您阅读-------------


On Mon,30 Jul 2007 06:32:55 -0400,Steve Holden写道:


>> [x for x in xrange(0,101)] == [y for y in xrange(101)]



特朗e



首先我想:为什么不必要的列表理解但令我惊讶:


在[33]中:xrange( 42)== xrange(42)

Out [33]:False


这很奇怪。


Ciao,

Marc''BlackJack''Rintsch


HI all

I am making an application with wxpython.
But I got a problem when I want to change the display string
according to process status.

I passed the frame to the processing function and use the
frame.txtobj to change displaying strings.

I found it is a bad method to do that.
Can any one tell me how to do that usually?
( How to separate GUI and Control code? )

Thank you.

解决方案

On Sun, 29 Jul 2007 23:34:14 -0700, Jia Lu wrote:

I am making an application with wxpython.
But I got a problem when I want to change the display string
according to process status.

I passed the frame to the processing function and use the
frame.txtobj to change displaying strings.

I found it is a bad method to do that.
Can any one tell me how to do that usually?
( How to separate GUI and Control code? )

One possibility here is to give a callback function into the worker
function that gets called while the function does it''s work. Simple
example:

def do_work(arguments, callback=lambda msg: None):
callback(''Start processing.'')
for percent in xrange(0, 101):
callback(''finished %d%%...'' % percent)
callback(''Done.'')

Ciao,
Marc ''BlackJack'' Rintsch


Marc ''BlackJack'' Rintsch wrote:

On Sun, 29 Jul 2007 23:34:14 -0700, Jia Lu wrote:

> I am making an application with wxpython.
But I got a problem when I want to change the display string
according to process status.

I passed the frame to the processing function and use the
frame.txtobj to change displaying strings.

I found it is a bad method to do that.
Can any one tell me how to do that usually?
( How to separate GUI and Control code? )


One possibility here is to give a callback function into the worker
function that gets called while the function does it''s work. Simple
example:

def do_work(arguments, callback=lambda msg: None):
callback(''Start processing.'')
for percent in xrange(0, 101):
callback(''finished %d%%...'' % percent)
callback(''Done.'')

>>[x for x in xrange(0, 101)] == [y for y in xrange(101)]

True

>>>

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------


On Mon, 30 Jul 2007 06:32:55 -0400, Steve Holden wrote:

>>[x for x in xrange(0, 101)] == [y for y in xrange(101)]

True

First I thought: Why the unnecessary list comprehension but to my surprise:

In [33]: xrange(42) == xrange(42)
Out[33]: False

That''s strange.

Ciao,
Marc ''BlackJack'' Rintsch


这篇关于如何在wxPython中单独编写GUI和事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆