python软件语言修改

编程入门 行业动态 更新时间:2024-10-25 11:32:31

python软件<a href=https://www.elefans.com/category/jswz/34/1770116.html style=语言修改"/>

python软件语言修改

我想知道如何使用Python更改Kivy语言内部标签的文本.

就像我如何将来自python的用户输入作为kivy中的标签文本.

(顺便说一句,我在实际程序中的格式是正确的,但我把它粘贴到stackoverflow)

如果我想让代码中的标签文本成为python中生成的随机数,我该如何进行呢?

from kivy.app import App

from kivy.lang import Builder

from kivy.uix.screenmanager import ScreenManager, Screen

from kivy.graphics import Color, Rectangle

from kivy.properties import ObjectProperty

# Create both screens. Please note the root.manager.current: this is how

# you can control the ScreenManager from kv. Each screen has by default a

# property manager that gives you the instance of the ScreenManager used.

Builder.load_string("""

:

GridLayout:

cols: 4

row_force_default: True

col_default_width: 175

row_default_height: 150

padding: 15

spacing: 15

canvas.before:

BorderImage:

# BorderImage behaves like the CSS BorderImage

border: 10, 10, 10, 10

source: '/Users/clayhigh/Desktop/kivy/aot.png'

pos: self.pos

size: self.size

Button:

text: 'Goto settings'

background_color: 1,0,0,0.5

on_press: root.manager.current = 'settings'

ButImage:

on_press: root.manager.current = 'UBW'

id: but

size_hint: .5, .5

opacity: 1 if self.state == 'normal' else .5

allow_stretch: True

keep_ratio: False

source: '.jpg'

Label:

center: but.center

text: "UBW"

color: 0.78,0.145,0.016,2

ButImage:

id: lh

size_hint: .5, .5

opacity: 1 if self.state == 'normal' else .5

allow_stretch: True

keep_ratio: False

source: '.jpg'

Label:

center: lh.center

text: "LH 2"

color: 0,0,0,1

ButImage:

id: ttl

size_hint: .5, .5

opacity: 1 if self.state == 'normal' else .5

allow_stretch: True

keep_ratio: False

source: '.jpg'

Label:

center: ttl.center

text: "TwTl"

color: 0,0,0,1

ButImage:

id: gris

size_hint: .5, .5

opacity: 1 if self.state == 'normal' else .5

allow_stretch: True

keep_ratio: False

source: '.jpg'

Label:

center: gris.center

text: "Gris"

color: 0,0,0,1

ButImage:

id: shig

size_hint: .5, .5

opacity: 1 if self.state == 'normal' else .5

allow_stretch: True

keep_ratio: False

source: '.jpg'

Label:

center: shig.center

text: "Shig"

color: 0,0,0,1

Button:

text: 'Test3'

background_color: 1,0,0,0.5

Button:

text: 'Test4'

background_color: 1,0,0,0.5

Button:

text: 'Quit'

background_color: 1,0,0,0.5

on_press: App.on_stop

:

GridLayout:

row_force_default: True

row_default_height: 100

cols: 2

canvas.before:

BorderImage:

# BorderImage behaves like the CSS BorderImage

border: 10, 10, 10, 10

source: '/Users/clayhigh/Desktop/kivy/ato.jpeg'

pos: self.pos

size: self.size

Button:

text: 'Button'

color: 0,0,.5

background_color: 1,0,0,1

Button:

text: 'Back to menu'

background_color: 1,0,0,1

on_press: root.manager.current = 'menu'

:

GridLayout:

row_force_default: True

row_default_height: 100

cols: 2

canvas.before:

Color:

rgb: .5, .5, .5

Rectangle:

pos: self.pos

size: self.size

Color:

rgb: 1, 1, 1

BorderImage:

# BorderImage behaves like the CSS BorderImage

border: 10, 10, 10, 10

source: '/Users/clayhigh/Desktop/kivy/fsn.jpg'

pos: self.pos

size: self.size

Button:

text: 'Back to menu'

color: 0,0,.5

on_press: root.manager.current = 'menu'

background_color: 1,0,0,1

Label:

id: AName

text: "F S/N: UBW"

font_size: '24sp'

""")

# Declare both screens

class MenuScreen(Screen):

pass

class SettingsScreen(Screen):

pass

class UBW(Screen):

pass

# Create the screen manager

sm = ScreenManager()

sm.add_widget(MenuScreen(name='menu'))

sm.add_widget(SettingsScreen(name='settings'))

sm.add_widget(UBW(name='UBW'))

class TestApp(App):

def build(self):

return sm

if __name__ == '__main__':

TestApp().run()

更多推荐

python软件语言修改

本文发布于:2024-02-11 18:03:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1682462.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语言   软件   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!