帮助从类中调用 def

发布于 2024-08-28 13:56:25 字数 1019 浏览 8 评论 0原文

菜鸟问题...

class msgbox:
    def __init__(self, lbl_msg = '', dlg_title = ''):
            self.wTree = gtk.glade.XML('msgbox.glade')    

            self.wTree.get_widget('dialog1').set_title(dlg_title) 
            self.wTree.get_widget('label1').set_text(lbl_msg)

            self.wTree.signal_autoconnect( {'on_okbutton1_clicked':self.done} )

    def done(self,w):
            self.wTree.get_widget('dialog1').destroy()

class Fun(object):
    wTree = None
    def __init__(self):      
        self.wTree = gtk.glade.XML( "main.glade" )
        self.wTree.signal_autoconnect( {'on_buttonOne' : self.one,} ) 

        gtk.main()

    @yieldsleep
    def one(self, widget, data=None):
        self.msg = msgbox('Please wait...','')
        yield 500
        self.msg = msgbox().done()  # <----------------???
        self.msg = msgbox('Done!','')

这样我得到一个错误: messageBox().done() TypeError: did() 恰好需要 2 个参数(给定 1 个)

我怎样才能使带有“请等待”的对话框在第二个带有“完成”的对话框出现之前关闭?

谢谢。

Noob question...

class msgbox:
    def __init__(self, lbl_msg = '', dlg_title = ''):
            self.wTree = gtk.glade.XML('msgbox.glade')    

            self.wTree.get_widget('dialog1').set_title(dlg_title) 
            self.wTree.get_widget('label1').set_text(lbl_msg)

            self.wTree.signal_autoconnect( {'on_okbutton1_clicked':self.done} )

    def done(self,w):
            self.wTree.get_widget('dialog1').destroy()

class Fun(object):
    wTree = None
    def __init__(self):      
        self.wTree = gtk.glade.XML( "main.glade" )
        self.wTree.signal_autoconnect( {'on_buttonOne' : self.one,} ) 

        gtk.main()

    @yieldsleep
    def one(self, widget, data=None):
        self.msg = msgbox('Please wait...','')
        yield 500
        self.msg = msgbox().done()  # <----------------???
        self.msg = msgbox('Done!','')

With this i get an error:
messageBox().done()
TypeError: done() takes exactly 2 arguments (1 given)

How can i make the dialog box with "please wait" to close before the second dialog box with "done" appears??

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪失控 2024-09-04 13:56:25

您似乎想要

self.msg.done()

关闭现有的“请稍候...”消息框。 msgbox().done() 创建一个新的消息框,然后在此新实例上调用 done

至于额外的参数,您没有使用它,因此将其从 done 的定义中删除:

def done(self):
    self.wTree.get_widget('dialog1').destroy()

Off Topic

Class msgbox 应该继承自 object > 这样你就得到了一个新样式类

msgbox 上定义一个 析构函数,然后你不需要显式调用 msgbox.done,您可能会忘记这样做。

class Msgbox(object):
    ...
    def __del__(self):
        self.wTree.get_widget('dialog1').destroy()

class Fun(object):
    ...
    @yieldsleep
    def one(self, widget, data=None):
        self.msg = Msgbox('Please wait...','')
        yield 500
        # actually, you probably need to delete the old self.msg
        # so it gets destroyed before the new message box is created
        del self.msg
        self.msg = Msgbox('Done!','')

It looks like you want

self.msg.done()

to close the existing "Please wait..." message box. msgbox().done() creates a new message box, then calls done on this new instance.

As for the extra parameter, you aren't using it, so remove it from the definition of done:

def done(self):
    self.wTree.get_widget('dialog1').destroy()

Off Topic

Class msgbox should inherit from object so you get a new-style class.

Define a destructor on msgbox and you don't need to explicitly call msgbox.done, which you might forget to do.

class Msgbox(object):
    ...
    def __del__(self):
        self.wTree.get_widget('dialog1').destroy()

class Fun(object):
    ...
    @yieldsleep
    def one(self, widget, data=None):
        self.msg = Msgbox('Please wait...','')
        yield 500
        # actually, you probably need to delete the old self.msg
        # so it gets destroyed before the new message box is created
        del self.msg
        self.msg = Msgbox('Done!','')
夏了南城 2024-09-04 13:56:25

您选择像这样定义 done 方法:

def done(self,w):

因此它确实需要两个参数 - 您调用它的 msgbox 实例,以及第二个神秘的 w 参数,然后它就不再使用它了。当您调用 done时,您不会传递那个神秘且完全无用的参数。那么为什么不将 def 更改为:

def done(self):

摆脱您当前需要但未提供的神秘、无用的 w 呢?

You've chosen to define the done method like this:

def done(self,w):

so it does need two arguments -- the msgbox instance you're calling it on, and a second mysterious w argument which it then never uses. When you call done, you don't pass that mysterious and totally useless argument. So why not change the def to:

def done(self):

getting rid of the mysterious, useless w which you're currently requiring but not supplying?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文