【发布时间】:2017-12-07 22:18:51
【问题描述】:
我是 kivy 的新手,并试图创建一个滚动视图,其中包含多个实时小部件。那种作品.. 但是订单项本身经常丢失自己的小部件,我经常收到此错误:
[CRITICAL] [Clock ] 警告,在下一帧之前完成了太多迭代。检查您的代码,或增加 Clock.max_iteration 属性
我读了很多“时钟”,阻塞了主线程等。我试图通过使用不同的线程来解决它。但仍然缺少小部件。
附上代码和图片。非常感谢您的帮助!谢谢!
我的控制器.kv
#:kivy 1.0
<Controller>:
size_hint: 1., 1.
pos_hint: {'center_x': .5, 'center_y': .5}
do_default_tab: False
tab1_pgbar: tab1_pgbar
layout_content: layout_content
tab1_refresh_btn: tab1_refresh_btn
TabbedPanelItem:
id: tab1
text: 'Browse'
BoxLayout:
id: bl
orientation: 'vertical'
ScrollView:
size_hint: 1.0,0.7
GridLayout:
id: layout_content
size_hint_y: None
height: self.minimum_height
cols: 1
row_default_height: '100dp'
row_force_default: True
spacing: 0, 5
BoxLayout:
size_hint: 1.0,None
height: 25
ProgressBar:
size_hint: 1.0,1.0
id: tab1_pgbar
max: 1000
Button:
id: tab1_refresh_btn
text: 'Refresh'
size: 100,25
on_release: root.refresh()
我的 kivyMain.py
import kivy
kivy.require('1.10.0')
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.clock import mainthread
import time
import threading
class myJobEntry(BoxLayout):
def __init__(self):
super(myJobEntry, self).__init__()
def addStuff(self,runindex,program):
b1 = Button(text=runindex,size_hint=(None,1.0),width=100)
b2 = TextInput(text=program,height=80)
hbox1 = BoxLayout(orientation='horizontal')
for i in range(10):
hbox1.add_widget(Button(text='{}'.format(i)))
vbox1 = BoxLayout(orientation='vertical')
vbox1.add_widget(hbox1)
vbox1.add_widget(b2)
self.add_widget(b1)
self.add_widget(vbox1)
class Controller(TabbedPanel):
'''Create a controller that receives a custom widget from the kv lang file.
Add an action to be called from the kv lang file.
'''
layout_content = ObjectProperty()
tab1_refresh_btn = ObjectProperty()
tab1_pgbar = ObjectProperty()
text_input = ObjectProperty()
def addSeveralObjects(self):
self.tab1_pgbar.value = 0
self.layout_content.enabled=False
for i in range(100):
myObj = myJobEntry()
myObj.addStuff('{}'.format(i),'i')
self.layout_content.add_widget(myObj)
self.updateBar()
def refresh(self):
self.tab1_refresh_btn.enabled = False
self.tab1_pgbar.value = 1
mythread = threading.Thread(target=self.addSeveralObjects)
mythread.start()
self.resetRefreshButton()
def resetRefreshButton(self):
self.tab1_refresh_btn.text = 'Last Refresh: {}'.format(time.ctime())
self.tab1_refresh_btn.enabled = True
def updateBar(self):
self.tab1_pgbar.value += 1
class ControllerApp(App):
def build(self):
return Controller()
if __name__ == '__main__':
ControllerApp().run()
【问题讨论】: