我需要将消息传递给错误对话框,以将其显示给用户。
第一次尝试
首选项对话框.py
dlgError = ErrorDialog ('Have you been messing with the configuration files?')
dlgError.run ()
错误对话框.py
global message = None
def __new__(cls, msg):
builder = get_builder('ErrorDialog')
new_object = builder.get_object('error_dialog')
new_object.finish_initializing(builder)
global message
message = msg
return new_object
def finish_initializing(self, builder):
# Get a reference to the builder and set up the signals.
self.builder = builder
self.ui = builder.get_ui(self)
global message
self.builder.get_object ('lblMessage').set_text (message)
第二次尝试
首选项对话框.py
dlgError = ErrorDialog ()
dlgError.message = 'Have you been messing with the configuration files?'
dlgError.run ()
错误对话框.py
global message = None
def __new__(cls):
builder = get_builder('ErrorDialog')
new_object = builder.get_object('error_dialog')
new_object.finish_initializing(builder)
return new_object
def finish_initializing(self, builder):
# Get a reference to the builder and set up the signals.
self.builder = builder
self.ui = builder.get_ui(self)
global message
self.builder.get_object ('lblMessage').set_text (message)
两者都抛出相同的异常;
self.builder.get_object ('lblMessage').set_text (message)
NameError: global name 'message' is not defined
请协助。我正在使用 Quickly、GTK 3 和 Python 2.7。