下面的代碼是我在得到一個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