python - 如何更改kivy中的按钮大小?
问题描述
我正在使用 kivy 在 Python 中编写程序,但无法更改在两个屏幕之间来回转换的按钮的大小
我想不出任何原因为什么我无法用“size: 75, 50”之类的东西来改变它的大小,是不是因为这个类是从 Screen 而不是 Button 继承的?
蟒蛇文件:
import kivy
from kivy.app import App
kivy.require("1.10.1")
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivy.uix.screenmanager import ScreenManager
class ScreenRoot(Screen):
pass
class OtherScreen(Screen):
pass
class ScreenUpkeep(ScreenManager):
pass
view = Builder.load_file("main.kv")
class MainApp(App):
def build(self):
return view
if __name__ == "__main__":
MainApp().run()
对应的.kv文件:
ScreenUpkeep:
ScreenRoot:
OtherScreen:
<ScreenRoot>:
name: "rootmain"
Button:
text: "Next Screen"
font_size: 40
on_release: app.root.current = "other"
size: 75, 50
<OtherScreen>:
name: "other"
Button:
text: "Return"
font_size: 40
on_release: app.root.current = "rootmain"
我只是希望能够更改按钮的大小,以便能够在每个屏幕上包含更多内容,例如文本和图片。
解决方案
您必须禁用size_hint,为了更好地可视化它,我将更改按钮的字体:
Button:
text: "Next Screen"
font_size: 12
on_release: app.root.current = "other"
size: 75, 50
size_hint: None, None # <---
推荐阅读
- javascript - 将 AJAX POST 请求从本地 .html 文件发送到 localhost:8080 时出错。CORS:“它没有 HTTP ok 状态。”
- swift - 在 Xcode 中,如何向我的 Mac 应用程序添加教程窗口,该窗口仅在首次启动时打开
- javascript - 如何在 JS 文件中使用 import?
- redux - Redux 测试:操作必须是普通对象。使用自定义中间件进行异步操作
- google-apps-script - 如何在 Google 脚本编辑器中引用单元格内的日期?
- r - 使用 ecdf 图中的值创建一个表
- visual-studio - 为什么 CRT 和 VS 内存分析的结果如此不同?
- mongodb - 使用 MongoDB 部分索引功能是否有效?
- bash - 列出 Cygwin/bash 脚本中包含空格的某些文件夹
- c++ - 内存分配心智图说明