我没有在python中动态更改按钮中的图像。 我不知道对基维语languaje使用该属性是否可以使用该变量。
我想更改python语言,因为我可以管理该按钮具有这些属性的时间。
main.py
import kivy
kivy.require('1.10.0')
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.config import Config
from kivy.graphics import Color, Rectangle
from kivy.properties import StringProperty
from kivy.uix.image import Image
from kivy.properties import ListProperty, NumericProperty
Config.set('graphics', 'width', 800)
Config.set('graphics', 'height', 580)
global TipoF
class MainWid(ScreenManager):
def __init__(self,**kwargs):
super(MainWid,self).__init__()
global TipoF
SALIDA_IMG = StringProperty("X.png")
ScrP = ScreenPrincipal(self)
wid = Screen(name='start')
wid.add_widget(ScrP)
self.add_widget(wid)
class ScreenPrincipal(BoxLayout):
global TipoF
def __init__(self, mainwid, **kwargs):
super(ScreenPrincipal,self).__init__()
self.mainwid = mainwid
def PulsaSalida(self, TipoFicha):
SALIDA_IMG = StringProperty("Y.png")
TipoF = TipoFicha
print (TipoF)
class BoxInfo(BoxLayout):
None
class BoxSalida(BoxLayout):
None
class ButtonSalida(Button):
None
class MainApp(App):
title = "Fichaje"
def build(self):
return MainWid()
if __name__ == '__main__':
MainApp().run()
main.kv
<MainWid>:
canvas:
Color:
rgb: 1,1,1
Rectangle:
pos: self.pos
size: self.size
<ScreenPrincipal>:
#SALIDA_IMG: SALIDA_IMG
orientation: 'vertical'
id: SCRPRIN
canvas:
Color:
rgb: .3,.3,.9,1
Rectangle:
pos: self.pos
size: self.size
BoxInfo:
size_hint_y: .70
BoxLayout:
canvas:
Color:
rgba: 1,1,1,1
Rectangle:
pos: self.pos
size: self.size
size_hint_y: .30
BoxSalida
id:boxsalida
ButtonSalida
on_release:
SCRPRIN.PulsaSalida("S")
<BoxSalida>:
padding: 5
canvas:
Color:
rgb: 1,.2,0
Rectangle:
pos: self.pos
size: self.size
<ButtonSalida>:
background_color: (1,.1,.4,.8)
text:"Salida"
id: BtnSalida
Image:
id: imagesal
#source: SALIDA_IMG
center_x: self.parent.center_x
center_y: self.parent.center_y
size:(130,130)
我尝试了几种方法,但都无效
最后一个错误:
NameError:名称'SALIDA_IMG'未定义