【发布时间】:2021-07-09 07:46:28
【问题描述】:
我有一个使用 python 和 kivy 在屏幕上显示文本的简单程序,但我无法更新我的屏幕。我尝试过使用下面写的内容,但它一直因错误“分段错误”而崩溃。我相信这个问题是由def _init_ 引起的,因为如果我删除它,故障就会消失,但屏幕仍然没有更新。
class ScreenDivider(Widget):
def __init__(self):
self.score = 12
#Clock.schedule_interval(self.UpdateText,1) I tried using this way but no luck
def UpdateText(self, dt):
self.score += 1
class Screen(App):
####################### Ignore from here ##################
stocksSearchArray = GrabStockList() # Grab the list of stocks I want to see
global stocksOnScreen # List of the stocks currently displayed on LED screen
global stocksOnScreenListInfo # The quote information for the stocks on screen
stocksOnScreen = []
stocksOnScreenListInfo = []
# Thread to handle constant data collection
thread_data_collector = threading.Thread(target=dataCollector_thread)
thread_data_collector.daemon = True
thread_data_collector.start()
# Thread to handle screen update
thread_whatsonscreen = threading.Thread(target=screenUpdate_thread, args=(stocksSearchArray,))
thread_whatsonscreen.daemon = True
thread_whatsonscreen.start()
# Handle user input
thread_inputHandle = threading.Thread(target=userInput_thread, args=(stocksSearchArray,))
thread_inputHandle.daemon = True
thread_inputHandle.start()
####################### Ignore to here ##################
# Build the screen
def build(self):
screen = ScreenDivider()
Clock.schedule_interval(screen.UpdateText, 1.0 / 60.0)
return screen
if __name__ == "__main__":
Screen().run()
.ky 文件
#:kivy 1.0.9
<ScreenDivider>:
name: 'program'
canvas:
Line:
points: 0,root.height*0.2,root.width,root.height*0.2
Label:
font_size: 70
center_x: root.width / 4
top: root.top - 50
text: str(root.score)
【问题讨论】: