python - 如何改变kivy窗口图标的大小

标签 python kivy border box

应用程序图标

我设计了一个示例代码,其中使用了我的应用程序图标,但它看起来非常小。现在我的图标大小是 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()

最佳答案

应用程序图标大小

我认为您无法更改应用程序的图标大小。

Application » icon

icon

Icon of your application. The icon can be located in the same directory as your main file.

Recommended 256x256 or 1024x1024? for GNU/Linux and Mac OSX 32x32 for Windows7 or less. <= 256x256 for windows 8 256x256 does work (on Windows 8 at least), but is scaled down and doesn’t look as good as a 32x32 icon.

文本周围的框边框

要在文本周围绘制一个框,请使用以下命令:

代码片段 - 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])

示例

main.py
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 - Box surround text

关于python - 如何改变kivy窗口图标的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52032247/

相关文章:

python - 如何在 PyQt4 中保持按钮相对于标签大小的变化不变

python - 无法获取窗口,中止

python-3.x - 尝试使用 PyInstaller 时出现权限错误

python - Kivy 应用程序无法在 Android 手机上运行,​​但可以在计算机上运行

Swift,ios 10 UIButton 边框

css - 增加边框和背景图像之间的空间

python - 如何使用 NumPy 数组算术 Python 对有限差分法进行矢量化?

python - 从一个函数在 Pandas Dataframe 中创建多列

wpf - 是否可以在 WPF ItemsControl 中模拟边框折叠(ala CSS)?

python - 无法将简单的python代码转换为haskell