Python-Kivy中的窗口大小调整
Kivy是Python中与平台无关的GUI工具。由于可以在Android,IOS,Linux和Windows等操作系统上运行,因此Kivy为您提供了编写代码一次并在不同平台上运行的功能。它基本上用于开发Android应用程序,但这并不意味着它不能在桌面应用程序上使用。
Kivy是该平台,其大小无关紧要,因为它可以进行自我调整,但是如果我们要在某种程度上固定大小(无论是高方向还是宽度方向还是不受边界限制)怎么办取决于用户需求。
示例
# When there is no fix window size i.e fully resizable according to user:from kivy.config import Config
# 0 being off 1 being on as in true / false you can use 0 or 1 && True or False
Config.set('graphics', 'resizable', True)
# import kivy module
import kivy
# this restrict the kivy version i.e below this kivy version you cannot use the app
kivy.require("1.9.1")
# base Class of your App inherits from the App class. app:always refers to the instance of your #application
from kivy.app import App
# if you not import label and use it through error
from kivy.uix.label import Label
# defining the App class
class MyLabelApp(App):
def build(self):
# label display the text on screen
# markup text with different colour
l2 = Label(text ="[color = ff3333][b]Hello !!!!!!!!!!![/b]
[/color]\n [color = 3333ff]World!!! !!:):):):)[/color]",
font_size ='20sp', markup = True)
return l2
# creating the object
label = MyLabelApp()# run the window
label.run()
# No resizing, fixed size with the width:
from kivy.config import Config
# 0 being off 1 being on as in true / false
# you can use 0 or 1 && True or False
Config.set('graphics', 'resizable', '0')
# fix the width of the window
Config.set('graphics', 'width', '500')
#fixing the height of the window
from kivy.config import Config
# 0 being off 1 being on as in true / false
# you can use 0 or 1 && True or False
Config.set('graphics', 'resizable', '0')
# fix the height of the window
Config.set('graphics', 'height', '400')
以上是 Python-Kivy中的窗口大小调整 的全部内容, 来源链接: utcz.com/z/352546.html