【发布时间】:2020-01-12 10:04:32
【问题描述】:
我正在尝试在 python 中使用 kivy 编写 GUI。在这个问题之前,我已经解决了我的代码问题:
Kivy error while trying to change the screen
现在,当我启动程序时,屏幕变白并崩溃,没有任何错误消息。
当我点击菜单屏幕中的一个按钮时,我正在尝试切换屏幕。
堆栈跟踪:
[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()
希望有人可以帮助我^^
【问题讨论】:
-
我不明白问题的描述 - “屏幕变白”是什么意思?全屏?基维窗口?它什么时候“崩溃”?白屏持续多久?
-
整个窗口是白色的,然后它在一秒钟后崩溃,让我们说立即。
标签: python python-3.x kivy