Python 在kivy应用程序上更改显示
当我运行应用程序时,会加载.kv布局,我输入必要的信息并调用set_info,但屏幕不会更改为set_info()中的布局,我以前没有做过任何gui编程,所以我会绕圈尝试解决这个问题。在文本框中输入信息后,如何更改显示Python 在kivy应用程序上更改显示,python,kivy,Python,Kivy,当我运行应用程序时,会加载.kv布局,我输入必要的信息并调用set_info,但屏幕不会更改为set_info()中的布局,我以前没有做过任何gui编程,所以我会绕圈尝试解决这个问题。在文本框中输入信息后,如何更改显示 class GetInformation(AnchorLayout): initial_bet = ObjectProperty() initial_odds = ObjectProperty() def set_info(self):
class GetInformation(AnchorLayout):
initial_bet = ObjectProperty()
initial_odds = ObjectProperty()
def set_info(self):
self.layout = GridLayout(cols=1, spacing=10, size_hint_y=None)
self.layout.bind(minimum_height=self.layout.setter('height'))
for k in offset_lay((Decimal(self.initial_bet.text),Decimal(self.initial_odds.text)):
btn = Button(text=str(k[0]), size_hint_y=None, height=40)
self.layout.add_widget(btn)
root = ScrollView(size_hint=(1, .80), size=(600, 600))
root.add_widget(self.layout)
return root
class AccountDetailsTextInput(TextInput):
next = ObjectProperty()
def _keyboard_on_key_down(self, window, keycode, text, modifiers):
if keycode[0] == 9: # 9 is the keycode for tab
self.next.focus = True
elif keycode[0] == 13: # 13 is the keycode for enter
self.parent.parent.set_odds()
else:
super(AccountDetailsTextInput, self)._keyboard_on_key_down(
window, keycode, text, modifiers)
class Offset(App):
def build(self):
return GetInformation()
如果name==“main”:
偏移量().run()
:
主播:“顶部”
主持人:对
首次下注:下注
初始赔率:赔率
网格布局:
科尔斯:2
行\默认\高度:“40dp”
行\强制\默认值:True
间距:“10dp”
填充:“10dp”
标签:
标记:正确
字体大小:“32sp”
文本:“[color=ff3333][/color][color=3333ff][b]输入您的初始股权:[/color]”
AccountDetailsTextInput:
id:打赌
下一个:赔率
标签:
标记:正确
字体大小:“32sp”
文本:“[color=ff3333][/color][color=3333ff][b]输入您的初始赔率:[/color]”
AccountDetailsTextInput:
id:赔率
下一步:打赌
按钮:
尺寸提示:无
#id:设为奇数
高度:“40dp”
正文:“计算”
背景颜色:.7、.7、1、1
哈利恩:“中心”
valign:“中间”
按:root.set\u info()
这一点就是问题所在。您创建了这个root
,并将布局添加到其中,但实际上从未将root
添加到任何内容中,因此它不会显示出来
解决方案是将您的root
添加到显示的小部件树中的某个现有小部件中
<GetInformation>:
anchor_y: "top"
anchor_x: "right"
initial_bet:bet
initial_odds:odds
GridLayout:
cols: 2
row_default_height: "40dp"
row_force_default: True
spacing: "10dp"
padding: "10dp"
Label:
markup:True
font_size: '32sp'
text: "[color=ff3333][/color] [color=3333ff][b]Enter your initial stake:[/color]"
AccountDetailsTextInput:
id:bet
next:odds
Label:
markup:True
font_size: '32sp'
text: "[color=ff3333][/color] [color=3333ff][b]Enter your initial odds:[/color]"
AccountDetailsTextInput:
id:odds
next: bet
Button:
size_hint_y: None
#id: set_odd
height: "40dp"
text: "Calculate"
background_color: .7, .7, 1, 1
halign: 'center'
valign: 'middle'
on_press: root.set_info()
root = ScrollView(size_hint=(1, .80), size=(600, 600))
root.add_widget(self.layout)
return root