启动程序后,Kivy崩溃而没有任何错误消息



我正在尝试用python中的kivy编写GUI。在这个问题之前,我已经有一个问题 我的代码问题得到了解决:
尝试更改屏幕时出现Kivy错误
现在,当我启动程序时,屏幕变白并崩溃,没有任何错误消息。
当我点击菜单屏幕中的一个按钮时,我正在尝试切换屏幕。

堆栈跟踪:

[INFO   ] [Kivy        ] v1.10.1
[INFO   ] [Python      ] v3.6.7 (default, Feb 28 2019, 07:28:18) [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 1050 Ti/PCIe/SSE2'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 5
[INFO   ] [GL          ] Shading version <b'4.50 NVIDIA'>
[INFO   ] [GL          ] Texture max size <32768>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
Process finished with exit code -1073741819 (0xC0000005)

Surface.py:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy_app_go.Control import HelperMethods
from kivy.properties import ObjectProperty
from kivy.graphics import Rectangle, Color, Line
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.core.window import Window
from kivy.uix.screenmanager import FadeTransition
from functools import partial

class MenuScreen(Screen):
def __init__(self, **kwargs):
super(Screen, self).__init__(**kwargs)
self.ScreenSize = Window.size
self.HelperMethodsInst = HelperMethods()
self.app = App.get_running_app()
lytmain = FloatLayout(size=self.ScreenSize)
lytbutton = BoxLayout(pos_hint={"y": 0.1, "x": 0.15}, size_hint=(2, 0.6), orientation='vertical', size=self.ScreenSize)
lblHeadline = Label(text="Choose your Go Mode", font_size=40, pos_hint={"y": 0.8, "x": 0.325},
size_hint=(0.35, 0.15))
btnHvH = Button(text="Human vs Human", size_hint=(0.35, 0.15),
on_release=lambda *args: self.HelperMethodsInst.switch_screen(goal_screen="go_screen", Screenmanager=self.app.WindowManagerInst.get_ScreenManager))
btnHvB = Button(text="Human vs Bot", size_hint=(0.35, 0.15),
on_release=lambda *args: self.HelperMethodsInst.switch_screen(goal_screen="go_screen", Screenmanager=self.app.WindowManagerInst.get_ScreenManager))
btnBvB = Button(text="Bot vs Bot", size_hint=(0.35, 0.15),
on_release=lambda *args: self.HelperMethodsInst.switch_screen(goal_screen="go_screen", Screenmanager=self.app.WindowManagerInst.get_ScreenManager))
self.add_widget(lytmain)
lytmain.add_widget(lblHeadline)
lytmain.add_widget(lytbutton)
lytbutton.add_widget(btnHvH)
lytbutton.add_widget(btnHvB)
lytbutton.add_widget(btnBvB)

class GoScreen(Screen):
def __init__(self, **kwargs):
super(GoScreen, self).__init__(**kwargs)
self.ScreenSize = Window.size
lytmain = FloatLayout(size=self.ScreenSize)
btnBack = Button(text="Back", size_hint=(0.25, 0.1))
self.add_widget(lytmain)
lytmain.add_widget(btnBack)

class WindowManager(ScreenManager):
def __init__(self):
# self.sm = ScreenManager(transition=FadeTransition(duration=0.15))
self.add_widget(MenuScreen(name="menu_screen"))
self.add_widget(GoScreen(name="go_screen"))
@property
def get_ScreenManager(self):
return self

class Surface(App):
def __init__(self):
super().__init__()
self.WindowManagerInst = WindowManager()
def build(self):
return self.WindowManagerInst
@staticmethod
def create_Surface():
return Surface().run()

def run():
SurfaceInst = Surface()
HelperMethodsInst = HelperMethods()

Control.py:

from kivy.uix.screenmanager import ScreenManager, Screen

class HelperMethods:
def switch_screen(self, Screenmanager, goal_screen):
print("pressed")
print(screenmanager)
print(screen)
screenmanager = goal_screen

main.py:

from kivy_app_go.Surface import Surface
if __name__ == "__main__":
Surface.create_Surface()

希望有人能帮助我^^

WindowManager类中,您需要修改__init__方法以包含对super的调用:

class WindowManager(ScreenManager):
def __init__(self):
super(WindowManager, self).__init__()
# self.sm = ScreenManager(transition=FadeTransition(duration=0.15))
self.add_widget(MenuScreen(name="menu_screen"))
self.add_widget(GoScreen(name="go_screen"))

我的 Kivy 应用程序没有显示任何信息消息或错误时遇到问题。在@el3phanten建议删除日志文件后已修复:

~/.kivy/config.ini

否,我可以看到信息和错误消息:

$ python3 main.py 
[INFO   ] [Logger      ] Record log in /home/user/.kivy/logs/kivy_21-11-03_16.txt
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "/home/user/dev/kiwi/venv/lib/python3.8/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0]
[INFO   ] [Python      ] Interpreter at "/home/user/dev/kiwi/venv/bin/python3"
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'4.3 (Compatibility Profile) Mesa 21.0.3'>
[INFO   ] [GL          ] OpenGL vendor <b'nouveau'>
[INFO   ] [GL          ] OpenGL renderer <b'NVC1'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 3
[INFO   ] [GL          ] Shading version <b'4.30'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [title       ] This is a info message.
[INFO   ] [title       ] This is a info message.
[INFO   ] [Clipboard   ] Provider: xsel(['clipboard_xclip'] ignored)
[INFO   ] [CutBuffer   ] cut buffer support enabled
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available
[WARNING] <kivy.uix.gridlayout.GridLayout object at 0x7ff070d98740> have no cols or rows set, layout is not triggered.
[INFO   ] [Base        ] Leaving application in progress...
[INFO   ] [title       ] This is a info message.

相关内容

最新更新