如何修复窗户上出现美学故障的Kivy缩放比例?

时间:2018-12-21 03:22:10

标签: python windows kivy

有没有办法使缩放的Kivy窗口在美学上令人愉悦?

默认情况下,当使用Kivy缩放窗口时,似乎窗口的内容随着窗口的缩放而拉伸,从而导致像素化混乱。只有释放窗口后,它才能正确呈现内容。

翘曲示例

我正在Windows中运行它。包含完整的点子列表

如果要运行它,这是我的代码。尝试缩放窗口,您应该会看到污点(如果我的kivy安装没有问题)

main.py

import kivy

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.properties import ObjectProperty

from kivy.config import Config
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')

class CalcGridLayout(GridLayout):
    display = ObjectProperty(None)

    def calculate(self, calculation):
        if calculation:
            try:
                self.display.text = str(eval(calculation))
            except Exception:
                self.display.text = "you MORON"

class CalculatorApp(App):

    def build(self):
        return CalcGridLayout()

calcApp = CalculatorApp()
calcApp.run()

calculator.kv

<CustButton@Button>:
    font_size: 32

<CalcGridLayout>:
    id: calculator
    display: entry
    rows: 5
    padding: 10
    spacing: 10

    BoxLayout:
        TextInput:
            id: entry
            font_size: 32
            multiline: False

    BoxLayout:
        spacing: 10
        CustButton:
            text: "7"
            on_press: entry.text += self.text
        CustButton:
            text: "8"
            on_press: entry.text += self.text
        CustButton:
            text: "9"
            on_press: entry.text += self.text
        CustButton:
            text: "+"
            on_press: entry.text += self.text

    BoxLayout:
        spacing: 10
        CustButton:
            text: "4"
            on_press: entry.text += self.text
        CustButton:
            text: "5"
            on_press: entry.text += self.text
        CustButton:
            text: "6"
            on_press: entry.text += self.text
        CustButton:
            text: "-"
            on_press: entry.text += self.text

    BoxLayout:
        spacing: 10
        CustButton:
            text: "1"
            on_press: entry.text += self.text
        CustButton:
            text: "2"
            on_press: entry.text += self.text
        CustButton:
            text: "3"
            on_press: entry.text += self.text
        CustButton:
            text: "*"
            on_press: entry.text += self.text

    BoxLayout:
        spacing: 10
        CustButton:
            text: "AC"
            on_press: entry.text = ""
        CustButton:
            text: "0"
            on_press: entry.text += self.text
        CustButton:
            text: "="
            on_press: calculator.calculate(entry.text)
        CustButton:
            text: "/"
            on_press: entry.text += self.text

点列表结果

absl-py             0.6.1
astor               0.7.1
certifi             2018.11.29
chardet             3.0.4
cycler              0.10.0
docutils            0.14
future              0.17.1
gast                0.2.0
graphviz            0.10.1
grpcio              1.16.1
gym                 0.10.9
h5py                2.8.0
idna                2.8
imageio             2.4.1
inflection          0.3.1
Keras-Applications  1.0.6
Keras-Preprocessing 1.0.5
Kivy                1.10.1
Kivy-examples       1.10.1
Kivy-Garden         0.1.4
kivy.deps.glew      0.1.10
kivy.deps.gstreamer 0.1.13
kivy.deps.sdl2      0.1.18
kiwisolver          1.0.1
lxml                4.2.5
Markdown            3.0.1
matplotlib          3.0.2
more-itertools      4.3.0
mpl-finance         0.10.0
neat-python         0.92
numpy               1.15.4
pandas              0.23.4
pandas-datareader   0.7.0
Pillow              5.3.0
pip                 18.1
protobuf            3.6.1
pyglet              1.3.2
Pygments            2.3.1
pyparsing           2.3.0
pypiwin32           223
python-dateutil     2.7.5
pytz                2018.7
pywin32             224
Quandl              3.4.5
requests            2.21.0
scipy               1.1.0
setuptools          20.10.1
six                 1.11.0
tensorboard         1.12.0
tensorflow          1.12.0
termcolor           1.1.0
urllib3             1.24.1
virtualenv          16.1.0
Werkzeug            0.14.1
wheel               0.32.3
wrapt               1.10.11

日志

[INFO   ] Logger: Record log in C:\Users\Daniel Warfield\.kivy\logs\kivy_18-12-23_1.txt
[INFO   ] Kivy: v1.10.1
[INFO   ] Python: v3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)]
[INFO   ] Factory: 194 symbols loaded
[INFO   ] Image: Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] Text: Provider: sdl2
[INFO   ] Window: Provider: sdl2
[INFO   ] GL: Using the "OpenGL" graphics system
[INFO   ] GL: GLEW initialization succeeded
[INFO   ] GL: Backend used <glew>
[INFO   ] GL: OpenGL version <b'4.5.0 NVIDIA 385.54'>
[INFO   ] GL: OpenGL vendor <b'NVIDIA Corporation'>
[INFO   ] GL: OpenGL renderer <b'GeForce GTX 970M/PCIe/SSE2'>
[INFO   ] GL: OpenGL parsed version: 4, 5
[INFO   ] GL: Shading version <b'4.50 NVIDIA'>
[INFO   ] GL: Texture max size <16384>
[INFO   ] GL: Texture max units <32>
[INFO   ] Window: auto add sdl2 input provider
[INFO   ] Window: virtual keyboard not allowed, single mode, not docked
[WARNING] Call to deprecated function __init__ in C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\listview.py line 845.Called from C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\lang\builder.py line 582 by _apply_rule().
[WARNING] Call to deprecated function __init__ in C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\adapters\simplelistadapter.py line 49.Called from C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\listview.py line 859 by __init__().
[WARNING] Call to deprecated function __init__ in C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\adapters\adapter.py line 111.Called from C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\adapters\simplelistadapter.py line 55 by __init__().
[WARNING] Call to deprecated function __init__ in C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\abstractview.py line 42.Called from C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\listview.py line 865 by __init__().
[WARNING] Call to deprecated function __init__ in C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\adapters\listadapter.py line 185.Called from D:\Documents\PersonalProjects\LineRiderBeautifier\KivyTests\kivyTest5\studentdb.kv line 49 by <module>().
[WARNING] Call to deprecated function __init__ in C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\adapters\adapter.py line 111.Called from C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\adapters\listadapter.py line 186 by __init__().
[INFO   ] Base: Start application main loop
[INFO   ] GL: NPOT texture support is available
[WARNING] Call to deprecated function __init__ in C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\selectableview.py line 38.Called from C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\listview.py line 593 by __init__().
[INFO   ] Base: Leaving application in progress...
[WARNING] stderr: Traceback (most recent call last):
[WARNING] stderr:   File "D:\Documents\PersonalProjects\LineRiderBeautifier\KivyTests\kivyTest5\main.py", line 28, in <module>
[WARNING] stderr:     dbApp.run()
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\app.py", line 799, in run
[WARNING] stderr:     self.load_kv(filename=self.kv_file)
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\app.py", line 596, in load_kv
[WARNING] stderr:     root = Builder.load_file(rfilename)
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\lang\builder.py", line 301, in load_file
[WARNING] stderr:     return self.load_string(data, **kwargs)
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\lang\builder.py", line 368, in load_string
[WARNING] stderr:     parser = Parser(content=string, filename=fn)
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\lang\parser.py", line 392, in __init__
[WARNING] stderr:     self.parse(content)
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\lang\parser.py", line 498, in parse
[WARNING] stderr:     self.execute_directives()
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\lang\parser.py", line 462, in execute_directives
[WARNING] stderr:     mod = __import__(package)
[WARNING] stderr:   File "D:\Documents\PersonalProjects\LineRiderBeautifier\KivyTests\kivyTest5\main.py", line 28, in <module>
[WARNING] stderr:     dbApp.run()
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\app.py", line 826, in run
[WARNING] stderr:     runTouchApp()
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\base.py", line 502, in runTouchApp
[WARNING] stderr:     EventLoop.window.mainloop()
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\core\window\window_sdl2.py", line 727, in mainloop
[WARNING] stderr:     self._mainloop()
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\core\window\window_sdl2.py", line 460, in _mainloop
[WARNING] stderr:     EventLoop.idle()
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\base.py", line 340, in idle
[WARNING] stderr:     self.dispatch_input()
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\base.py", line 325, in dispatch_input
[WARNING] stderr:     post_dispatch_input(*pop(0))
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\base.py", line 231, in post_dispatch_input
[WARNING] stderr:     listener.dispatch('on_motion', etype, me)
[WARNING] stderr:   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\core\window\__init__.py", line 1360, in on_motion
[WARNING] stderr:     self.dispatch('on_touch_down', me)
[WARNING] stderr:   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\core\window\__init__.py", line 1376, in on_touch_down
[WARNING] stderr:     if w.dispatch('on_touch_down', touch):
[WARNING] stderr:   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\widget.py", line 460, in on_touch_down
[WARNING] stderr:     if child.dispatch('on_touch_down', touch):
[WARNING] stderr:   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\widget.py", line 460, in on_touch_down
[WARNING] stderr:     if child.dispatch('on_touch_down', touch):
[WARNING] stderr:   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\behaviors\button.py", line 151, in on_touch_down
[WARNING] stderr:     self.dispatch('on_press')
[WARNING] stderr:   File "kivy\_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
[WARNING] stderr:   File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
[WARNING] stderr:   File "kivy\_event.pyx", line 1098, in kivy._event.EventObservers._dispatch
[WARNING] stderr:   File "C:\Users\Daniel Warfield\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\lang\builder.py", line 64, in custom_callback
[WARNING] stderr:     exec(__kvlang__.co_value, idmap)
[WARNING] stderr:   File "D:\Documents\PersonalProjects\LineRiderBeautifier\KivyTests\kivyTest5\studentdb.kv", line 34, in <module>
[WARNING] stderr:     on_press: root.submit_student()
[WARNING] stderr:   File "kivy\weakproxy.pyx", line 30, in kivy.weakproxy.WeakProxy.__getattr__
[WARNING] stderr: AttributeError: 'StudentDB' object has no attribute 'submit_student'

0 个答案:

没有答案