首页 > 解决方案 > 如何在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()

标签: pythonkivyborderbox

解决方案


应用程序图标大小

我不认为您可以更改应用程序的图标大小。

应用 » 图标

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()

输出

Img01 - 框环绕文本


推荐阅读