我目前正在编写一个简单的应用程序,以便在按下按钮后显示一些文本。但是,该布局在我的手机上与在我的PC上完全不同。 更改.kv中标签的位置无效。没有改变。 为了构建该应用程序,我使用了带有buildozer的Ubuntu虚拟盒子。
屏幕截图(Galaxy s9 +)
Main.py:
import kivy
import random
import math
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.relativelayout import RelativeLayout
def roundup(x):
return int(math.ceil(x / 5.0)) * 5
x = random.randint(0,29)
tempo = roundup(random.randint(80,150))
Tonart = ["GDur #","eMoll #","DDur ##","hMoll ##","ADur ###","fisMoll ###","EDur ####","cisMoll ####","HDur ######","gisMoll #####","FisDur ######","disMoll ######","CisDur #######","aisMoll #######","FDur ♭","dMoll ♭","BDur ♭♭","gMoll ♭♭","EsDur ♭♭♭","cMoll ♭♭♭","AsDur ♭♭♭♭","fMoll ♭♭♭♭","DesDur ♭♭♭♭♭","bMoll ♭♭♭♭♭","GesDur ♭♭♭♭♭♭","esMoll ♭♭♭♭♭♭","CesDur ♭♭♭♭♭♭♭","asMoll ♭♭♭♭♭♭♭","CDur","aMoll"]
Kreuze = ["Fis","Cis","Gis","Dis","Ais","Eis","His"]
Bs = ["B","Es","As","Des","Ges","Ces","Fes"]
class Controller(RelativeLayout):
def __init__(self):
super(Controller, self).__init__()
def btn_clk(self):
self.lbl6.text = str(tempo)
if x == 0 or x == 1:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Kreuze[0:1])
elif x == 2 or x == 3:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Kreuze[0:2])
elif x == 4 or x == 5:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Kreuze[0:3])
elif x == 6 or x == 7:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Kreuze[0:4])
elif x == 8 or x == 9:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Kreuze[0:5])
elif x == 10 or x == 11:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Kreuze[0:6])
elif x == 12 or x == 13:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Kreuze[0:7])
elif x == 14 or x == 15:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Bs[0:1])
elif x == 16 or x == 17:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Bs[0:2])
elif x == 18 or x == 19:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Bs[0:3])
elif x == 20 or x == 21:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Bs[0:4])
elif x == 22 or x == 23:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Bs[0:5])
elif x == 24 or x == 25:
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Bs[0:6])
elif x == 26 or x == 27:
print("Tonart:",Tonart[x],"also:")
print(Kreuze[0:2])
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = str(Bs[0:7])
elif x == 28 or x == 29:
print("Tonart:",Tonart[x],"also:")
print(Kreuze[0:2])
self.lbl.text = "Tonart:"
self.lbl2.text = Tonart[x]
self.lbl3.text = "also:"
self.lbl4.text = "KEINE VORZEICHEN DIGGAH"
class ActionApp(App):
def build(self):
return Controller()
myApp = ActionApp()
myApp.run()
action.kv:
<Controller>:
lbl: label1
lbl2: label2
lbl3: label3
lbl4: label4
lbl5: label5
lbl6: label6
RelativeLayout:
Button:
text: 'Key und Bpm generieren'
on_press: root.btn_clk()
pos: 0,50
Label:
id: label1
text: 'Tonart:'
pos: -158, -272
Label:
id: label2
text: "..."
pos: -45, -272
Label:
id: label3
text: "also:"
pos: 40, -272
Label:
id: label4
text: "..."
pos: 200, -272
Label:
id: label5
text: "Bpm:"
pos: -360, -272
Label:
id: label6
text: "..."
pos: -325, -272