python/kivy中的标签文本

python/kivy中的标签文本,python,kivy,Python,Kivy,我正在编写一个带有两个按钮的代码,用kivy将随机文本返回到标签,但我无法让这两个按钮返回同一行上的文本,我希望其中一个按钮覆盖第二个按钮在同一行上显示的内容 : 盒子布局: orientation: 'vertical' pos: self.pos Label: id: label1 text: root.truths Label: id: label2 text: root.dares

我正在编写一个带有两个按钮的代码,用kivy将随机文本返回到标签,但我无法让这两个按钮返回同一行上的文本,我希望其中一个按钮覆盖第二个按钮在同一行上显示的内容

: 盒子布局:

    orientation: 'vertical'
    pos: self.pos
    Label:
        id: label1
        text: root.truths
    Label:
        id: label2
        text: root.dares

    GridLayout:
        cols: 2
        spaccing: 20
        padding: 25
        Button:
            text: 'Truth'
            on_press: root.truthkey()
        Button:
            text: "Dare"
            on_press: root.darekey()
上面是kv文件中的代码,python文件中的代码如下所示

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
import random
from kivy.properties import StringProperty


class TruthandDare(BoxLayout):
    truths = StringProperty()
    dares = StringProperty()

    def __init__(self, **kwargs):
        super(TruthandDare, self).__init__(**kwargs)
        self.truths=str(random.choice(['a']))
        self.dares=str(random.choice(['b']))

    def truthkey(self):
        self.truths=str(random.choice(['What is your biggest fear in a relationship',
            'What was your funniest date ever',
            'How many kids would  you  like to have',
            'What was your childhood nickname',
            'what is your favourite movie',
            'what is your favourite food',
            'what is your dream job',
            'if you were trapped on an island for 3 days, what would you take with you',
            'Do you prefer apple or android device',
            'What is your best talent',
            'Do you believe in love at first sight',
            'What is your dream wedding',
            'if you could change one thing on your body, what would it be']))

    def darekey(self):
        self.dares = str(random.choice(['b','c','d','e','f']))



class TruthDareApp(App):
    def build(self):
        return TruthandDare()

if __name__=='__main__':
    TruthDareApp().run()

也许你可以这样做:

Button:
    on_press: print(f'{root.truths}, {root.dares}')

如果不告诉我,我希望这会有所帮助。

您有什么问题?你收到错误信息了吗?没有任何错误,上面的程序运行正常,但我想让两个按钮都显示在一行上