每次我运行时,Python,Kivy,Label都会切换位置,这是一个错误吗?

时间:2018-12-14 17:06:22

标签: python kivy

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.core.audio import SoundLoader
from kivy.clock import Clock
import character
from kivy.config import Config
from kivy.uix.image import Image
from kivy.uix.label import Label

    self.background=Image(source="Pics\\backgroundtemp.png",pos_hint ={"x":0,"y":0.2})
    self.add_widget(self.background)
    for i in range (3):
        self.playerR[i] = character.Character("DIO","R",size_hint=(0.35,0.35),pos_hint={"x":0.7,"y":0.4})
        self.playerL[i] = character.Character("DIO","L",size_hint=(0.35,0.35),pos_hint={"x":-0.05,"y":0.4})
    self.add_widget(self.playerR[0])
    self.add_widget(self.playerL[0])
    print self.width
    self.abilityLabel = [Label(text=i.name, font_size=30, color = (1, 1, 1, 1)) for i in self.playerL[0].abilities]
    self.abilityLabel.insert(0, Label(text="switch", font_size=30, color= (1, 1, 1, 1), pos_hint={"x": 0.05, "y": -0.35}))
    self.abilityLabel[1].pos_hint = {"x": -0.4, "y": -0.3}
    self.abilityLabel[2].pos_hint = {"x": -0.15, "y": -0.3}
    self.abilityLabel[3].pos_hint = {"x": -0.4, "y": -0.45}
    self.abilityLabel[4].pos_hint = {"x": -0.15, "y": -0.45}
    self.nameLabels =[Label(text = self.playerL[0].name), Label(text = self.playerR[0].name)]
    self.nameLabels[0].pos_hint = {"x":-0.4, "y": 0.45}
    self.nameLabels[1].pos_hint = {"x": 0.4, "y": 0.45}
    self.imageAbility = [Image(source = "Pics\AbilityTempBack.png", allow_stretch= True,keep_ratio = False,size_hint = (0.15,0.1)) for i in range(5)]
    self.imageAbility[0] = Image(source="Pics\AbilityTempBack.png", allow_stretch=True, keep_ratio=False,size_hint=(0.1, 0.1))

    self.imageAbility[0].pos_hint = {"x": 0.5, "y": 0.1}
    self.imageAbility[1].pos_hint = {"x": 0.05, "y": 0.15}
    self.imageAbility[2].pos_hint = {"x": 3, "y": 0.1}
    self.imageAbility[3].pos_hint = {"x": 3, "y": 0.1}
    self.imageAbility[4].pos_hint = {"x": 3, "y": 0.1}

    for i in range(len(self.imageAbility)):
        self.add_widget(self.imageAbility[i])

    for i in range(len(self.abilityLabel)):
        self.add_widget(self.abilityLabel[i])

    for i in range(2):
        self.nameLabels[i].font_size = 40
        self.add_widget(self.nameLabels[i])

这里是角色

from kivy.core.audio import SoundLoader
from kivy.uix.image import Image

class Character(Image):  # Character is also Image
    def __init__(self, name, side, **kwargs):
        super(Character, self).__init__(**kwargs)  # because we defined char as an image we need this sentence
        self.name = name
        self.side = side
        self.health = 100
        self.maxHealth = 100
        self.strength = 100
        self.defense = 100
        self.attack_speed = 100
        self.speedBuff = 1
        self.powerBuff = 1
        self.defenseBuff = 1
        self.abilities = {Ability("temp1" , side),Ability("temp2" , side),Ability("temp3" ,side),Ability("temp4",side)}
        self.source = "Pics\chr"+name+side+".png"

无论如何,这似乎是一个错误,并且确实令人沮丧,因为它确实是随机的,并且它在我按代码运行时每两次都会改变,这可能是kivy本身的问题,而不是某些问题否则,这是一张有关它的意图和它有时如何显示的图片

0 个答案:

没有答案