下面的代码是我在得到一个GUI应用程序来更新原有的企图其字体等,,当用户在config.ini文件设置改变了它:差异
def on_config_change(self, config, section, key, value):
"""
sets font,size colour etc..
when user changes in settings.
"""
if config is self.config:
token = (section, key)
if token == ('Font', 'button_font'):
print('Our button font has been changed to', value)
GetInformation().lay_button.font_size = str(value)
GetInformation().bet_button.font_size = str(value)
def build(self):
self.config.write()
return GetInformation()
我的代码更新了配置,但屏幕从未更新,无需重新启动应用程序。
下面的代码工作:
def on_config_change(self, config, section, key, value):
"""
sets font,size colour etc..
when user changes in settings.
"""
if config is self.config:
token = (section, key)
if token == ('Font', 'button_font'):
print('Our button font has been changed to', value)
self.getInformation.lay_button.font_size = str(value)
self.getInformation.bet_button.font_size = str(value)
def build(self):
self.config.write()
self.getInformation = GetInformation()
return self.getInformation
是什么调用GetInformation()lay_button.font_size 和self.getInformation.lay_button.font_size之间的区别?
谢谢,让我感到困惑的是在使用self.getInformation = GetInformation()之前使用self.getInformation。 –
在函数的情况下,语句的执行顺序与其在文件中的位置不相关。这个代码当然只适用于在'on_config_change'之前调用'build'函数。如果不是这种情况,你最终会得到'AttributeError',因为'self.getInformation'不存在。 – Cilyan