【问题标题】:My kivy code isnt showing an image on the button我的 kivy 代码没有在按钮上显示图像
【发布时间】:2020-10-13 19:55:18
【问题描述】:

我写这个是为了显示一个带有给定图像的按钮

import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.button import Button

class DatesPage(FloatLayout):
    def __init__(self, **kwargs):
        super(DatesPage, self).__init__(**kwargs)
        self.add_butt = Button(background_normal='plus_butt.png', size_hint=(0.2, 0.1))
        self.add_widget(self.add_butt)

class DiaryApp(App):
    def build(self):
       return DatesPage()

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

如何确保图像显示在按钮上

【问题讨论】:

    标签: python-3.x user-interface button kivy


    【解决方案1】:

    您无法使用此代码获得窗口。因为你没有正确调用 DiaryApp 类。在类名后加括号。

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

    【讨论】:

    • 我纠正了它,但我仍然没有得到@320V 的输出
    • 您是遇到错误还是现在看不到按钮图像?如果你有请分享错误。因为它适用于我的 linux.Python 3.6.9 、kivy 1.11.1 版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多