kivy: import causing window to open

Software Versions

  • Python: 3.10
  • OS: Windows 10
  • Kivy: 2.2.1
  • Kivy installation method: pip

Describe the bug A import from kivy.core.window import Window should not open a window. That means that the module init is executing code with massive unexpected side effects. Further this prevents the use of kivy in a GUI process, other than the main process and is a major obstacle for multiprocessing.

Constructor code execution that causes side effects, is a major design problem in all OOP languages and should be considered a bug.

Expected behavior No kivy.core.window module init side effects

To Reproduce A short, runnable example that reproduces the issue with latest kivy master.

Code and Logs and screenshots

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.core.window import Window
from multiprocessing import Process

class DoClose(App):

def build(self):
    self.window = GridLayout()
    self.window.cols = 1
    self.window.size_hint = (0.6, 0.7)
    self.window.pos_hint = {"center_x": 0.5, "center_y": 0.5}
    self.button = Button(text="SHUTDOWN", size_hint=(1, 0.4), bold=True, background_color='#00FFCE')
    self.button.bind(on_press=self.stop)
    self.window.add_widget(self.button)
    return self.window

def gogogo():
DoClose().run()

if name == "main":
proc = Process(name="gcon", target=gogogo)
proc.start()

image

Additional context This issue has been suggested by @akshayaurora as follow-up to #8338

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 19 (17 by maintainers)

Most upvoted comments

Yeah I agree may it would be proper to address #8348 in a separate pr and not this one.