我是Python和Kivy的新手。在取得一些進展之後,我碰到了一堵磚牆,沒有任何互聯網搜索能夠找到答案。Kivy。更改佈局
我有一個網格佈局選擇菜單開始一個python/kivy腳本。然後,我想「單擊下一步」,並將GridLayout替換爲BoxLayout以顯示輸出。該Python腳本是:
import sys
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.checkbox import CheckBox
from kivy.uix.gridlayout import GridLayout
from kivy.uix.pagelayout import PageLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.properties import StringProperty, ListProperty, DictProperty
from kivy.uix.widget import Widget
from brp_stats import *
from dice_roller import *
#from display import *
race = ''
statblock = ''
class Test(GridLayout):
def printcharacter(self,my_sb,my_cr,my_scm,my_scb):
printable_stats = print_stats(my_sb)
printable_rolls = print_rolls(my_cr)
printable_scm = print_scm(my_scm)
printable_scb = print_scb(my_scb)
self.clear_widgets()
self.add_widget(Label(text_size=(300, None),
text='Stats\n' + str(printable_stats)))
self.add_widget(Label(text_size=(300, None),
text='Rolls\n' + str(printable_rolls)))
self.add_widget(Label(text_size=(300, None),
text='SCM\n' + str(printable_scm)))
self.add_widget(Label(text_size=(300, None),
text='SCB\n' + str(printable_scb)))
wayout = Button(text='Way Out')
self.add_widget(wayout)
wayout.bind(on_press=self.canvas.clear)
# def bar():
# print ("BAR")
def human(self,a,b):
if b==True:
self.Status="human"
race=self.Status
statblock = human()
characteristic_rolls = rolls(statblock)
skill_category_modifiers = scm(statblock)
skill_category_bonuses = scb(statblock)
# TestApp.foo()
# Test.bar()
Test.printcharacter(\ self,statblock,characteristic_rolls,skill_category_modifiers,skill_category_bonuses)
class TestApp(App):
# def foo():
# print ("FOO")
def build(self):
self.title="BRP Character Generator"
return Test()
#### MAIN CODE ####
if __name__ == '__main__':
TestApp().run()
而且KV腳本
<Test>:
cols: 2
canvas:
Color:
rgb: .2,.2,.2
Rectangle:
pos: self.pos
size: self.size
Label:
text: 'Human'
CheckBox:
group: 'race_group'
on_active: root.human(*args)
Button:
text: 'Next'
on_press: printcharacter()
發生了什麼事是我選擇(在本例人)的選項。它應該等到我點擊「下一步」之後再顯示結果。但是,只要我選擇Human,它立即將結果打印在GridLayout中。兩個問題映入腦海,這我在這裏希望專家能夠協助的:
1)爲什麼選擇屏幕沒有等到我已單擊下一步顯示結果之前? 2)當我顯示第二個屏幕時,如何從Grid到Box交換佈局?
任何指針或建議將受到感謝。
問候, 科林
這裏是我試過,通常進口後(編輯爲簡潔起見) '類顯示器(控件): 佈局= BoxLayout的(方向= '垂直') 高清print_a_label(個體經營): 佈局= BoxLayout的(方向= '垂直') print_this =標籤(文本= '按下的按鈕1') layout.add_widget(print_this) 類TestApp(APP): DEF建立(個體): 佈局= GridLayout的(COLS = 2) button1 = Button(text ='Press This') layout.add_widget(button1) button1.bind (on_press = Display.print_a_label) return layout'它仍然不顯示BoxLayout –