如何在 Kivy 中固定小部件? (或 window)
How do I make a widget fixed in Kivy? ( or a window)
我在 Python 3.9
中使用 kivy
我有 window 分辨率为 800x600
Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width', 800)
Config.set('graphics', 'height', 600)
出于某种原因,这仍然允许我稍后更改 window 大小,如果有办法更改,请帮助。
所以我在 .kv 文件中设置了几个按钮,当我 运行 它时一切 运行 都很顺利。当我更改 window 的大小时出现问题(通过全屏或只是弄乱 window)。当我这样做时,按钮开始随机改变大小并且变得混乱。有没有办法让按钮随尺寸自动调整?还是只是让住宿保持固定大小而根本不改变?谢谢
更新:
Kivy 文件
search : search
explore : explore
GridLayout:
cols:1
size: root.width -500, root.height -550
pos: 250,350
GridLayout:
cols:1
TextInput:
id: search
multinline : False
Button:
text:"Search"
Python 文件
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.config import Config
from kivy.properties import ObjectProperty
import subprocess
Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width', 800)
Config.set('graphics', 'height', 600)
class MyGrid(Widget):
explore = ObjectProperty(None)
def btn_touch_up(self):
from subprocess import Popen, PIPE
subprocess.Popen(['python', 'UI_1.py'])
exit()
class MyApp(App):
def build(self):
return MyGrid()
来自Config
documentation:
Configuration options control the initialization of the App. In order
to avoid situations where the config settings do not work or are not
applied before window creation (like setting an initial window size),
Config.set should be used before importing any other Kivy modules.
Ideally, this means setting them right at the start of your main.py
script.
只需移动行:
from kivy.config import Config
Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width', 800)
Config.set('graphics', 'height', 600)
到您的 py
文件的最顶部。
我在 Python 3.9
中使用 kivy我有 window 分辨率为 800x600
Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width', 800)
Config.set('graphics', 'height', 600)
出于某种原因,这仍然允许我稍后更改 window 大小,如果有办法更改,请帮助。
所以我在 .kv 文件中设置了几个按钮,当我 运行 它时一切 运行 都很顺利。当我更改 window 的大小时出现问题(通过全屏或只是弄乱 window)。当我这样做时,按钮开始随机改变大小并且变得混乱。有没有办法让按钮随尺寸自动调整?还是只是让住宿保持固定大小而根本不改变?谢谢
更新:
Kivy 文件
search : search
explore : explore
GridLayout:
cols:1
size: root.width -500, root.height -550
pos: 250,350
GridLayout:
cols:1
TextInput:
id: search
multinline : False
Button:
text:"Search"
Python 文件
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.config import Config
from kivy.properties import ObjectProperty
import subprocess
Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width', 800)
Config.set('graphics', 'height', 600)
class MyGrid(Widget):
explore = ObjectProperty(None)
def btn_touch_up(self):
from subprocess import Popen, PIPE
subprocess.Popen(['python', 'UI_1.py'])
exit()
class MyApp(App):
def build(self):
return MyGrid()
来自Config
documentation:
Configuration options control the initialization of the App. In order to avoid situations where the config settings do not work or are not applied before window creation (like setting an initial window size), Config.set should be used before importing any other Kivy modules. Ideally, this means setting them right at the start of your main.py script.
只需移动行:
from kivy.config import Config
Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width', 800)
Config.set('graphics', 'height', 600)
到您的 py
文件的最顶部。