python - 如何在kivy中更改窗口图标的大小
问题描述
应用程序图标
我设计了一个示例代码,我在其中使用了我的应用程序图标,但它看起来非常小。现在我的图标大小是 100 x 36。当我运行程序时,图标看起来非常小。我正在尝试增加它的大小,以便我们可以看到它。
文本周围的边框
而且我只需要用框为文本加边框,但边框是为整个标签区域创建的。
问题
- 是否可以增加图标的大小?
- 我只需要将标签文本框起来。
我的示例代码:
from kivy.uix.floatlayout import FloatLayout
from kivy.app import App
from kivy.lang import Builder
Builder.load_string('''
<MainScreen>:
GridLayout:
orientation: 'vertical'
cols: 1
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
GridLayout:
padding: [10, 10, 10, 10]
spacing: [10,10]
orientation: 'vertical'
cols: 1
size_hint: 1, .1
canvas:
Color:
rgba: .1, .1, 1, .9
Line:
width: 1.
rectangle: (self.x, self.y, self.width, self.height)
Label:
text: 'INPUTS'
color: 0,0,0,1
GridLayout:
padding: [10, 10, 10, 10]
spacing: [10,10]
orientation: 'vertical'
cols: 1
size_hint: 1, .1
canvas:
Color:
rgba: .1, .1, 1, .9
Line:
width: 1.
rectangle: (self.x, self.y, self.width, self.height)
Label:
text: 'OUTPUTS'
color: 0,0,0,1
''')
class MainScreen(FloatLayout):
def __init__(self, **kwargs):
super(MainScreen, self).__init__(**kwargs)
class TestApp(App):
def build(self):
self.icon = 'fif.png'
self.title = 'sample_v_1.1'
return MainScreen()
if __name__ == "__main__":
TestApp().run()
解决方案
应用程序图标大小
我不认为您可以更改应用程序的图标大小。
icon
您的应用程序的图标。该图标可以位于与主文件相同的目录中。
推荐 256x256 还是 1024x1024?适用于 Windows7 或更低版本的 GNU/Linux 和 Mac OSX 32x32。<= 256x256 for windows 8 256x256 确实可以工作(至少在 Windows 8 上),但是按比例缩小并且看起来不如 32x32 图标好。
文本周围的框边框
要在文本周围绘制一个框,请使用以下命令:
片段 - kv 文件
Label:
canvas:
Color:
rgba: .1, .1, 1, .9
Line:
width: 1.
rectangle: (int(self.center_x - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.), self.texture_size[0], self.texture_size[1])
例子
主文件
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
Builder.load_string('''
<MainScreen>:
inputs: inputs
outputs: outputs
GridLayout:
orientation: 'vertical'
cols: 1
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
GridLayout:
padding: [10, 10, 10, 10]
spacing: [10,10]
orientation: 'vertical'
cols: 1
size_hint: 1, .1
Label:
canvas:
Color:
rgba: .1, .1, 1, .9
Line:
width: 1.
rectangle: (int(self.center_x - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.), self.texture_size[0], self.texture_size[1])
id: inputs
text: 'INPUTS'
color: 0,0,0,1
GridLayout:
padding: [10, 10, 10, 10]
spacing: [10,10]
orientation: 'vertical'
cols: 1
size_hint: 1, .1
Label:
canvas:
Color:
rgba: .1, .1, 1, .9
Line:
width: 1.
rectangle: (int(self.center_x - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.), self.texture_size[0], self.texture_size[1])
id: outputs
text: 'OUTPUTS'
color: 0,0,0,1
''')
class MainScreen(FloatLayout):
pass
class TestApp(App):
icon = 'ac013.png'
title = 'sample_v_1.1'
def build(self):
return MainScreen()
if __name__ == "__main__":
TestApp().run()
输出
推荐阅读
- file - 如何在命令行 Racket 的 REPL 中加载和使用 .rkt 文件?
- c# - 如何注册强类型 SignalR Core 集线器?
- python - 在中断和尝试更改循环值之后,这可能是其他条件吗?
- sql - 向主从表 Delphi 添加新值时绑定外键
- r - R中从宽到长的复杂整形(从原始变量名中提取多个东西)
- python - Python:列表分组
- excel - 打开 excel 文件而不在 VB.Net 中给出完整路径
- azure - 在启动时使用 Database.Migrate() 时出现 Azure Web App 部署错误
- sqlite - 如何选择表中具有重复值的行?
- python - 海龟图形:如何实现暂停功能?