I am creating an app using Kivy, a Python GUI library, and have combined Multiprocessing and Kivy to create the following code. The following code works fine.
However, when I uncommentout the Import statement, it creates one additional black empty window the same size as Kivy.
How can I get rid of the black window?
from kivy.app import App
from kivy.uix.widget import Widget
from multiprocessing import Process, Value
from kivy.lang import Builder
"""
from kivy.uix.checkbox import CheckBox
from kivy.uix.spinner import Spinner
from kivy.properties import StringProperty,NumericProperty,ObjectProperty, BooleanProperty
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.treeview import TreeView, TreeViewLabel, TreeViewNode
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.progressbar import ProgressBar
from kivy.uix.button import Button
"""
Builder.load_string("""
<TextWidget>:
BoxLayout:
orientation: 'vertical'
size: root.size
Button:
id: button1
text: "start"
font_size: 48
on_press: root.buttonClicked()
Label:
id: lab
text: 'result'
""")
class TextWidget(Widget):
def __init__(self, **kwargs):
super(TextWidget, self).__init__(**kwargs)
self.process_test = None
self.proc = None
# shared memory
self.count = Value('i', 0)
self.proc = start_process(self.count)
self.ids.button1.text = "stop"
def buttonClicked(self):
if self.ids.button1.text == "start":
self.ids.button1.text = "stop"
else:
if self.proc:
self.proc.kill()
self.ids.button1.text = "start"
self.ids.lab.text = str(self.count.value)
class TestApp(App):
def __init__(self, **kwargs):
super(TestApp, self).__init__(**kwargs)
self.title = 'testApp'
def build(self):
return TextWidget()
def start_process(count):
process_test = Process(target=p_test, args=[count], daemon=True)
process_test.start()
return process_test
def p_test(count):
i = 0
while True:
print(i)
i = i + 1
with count.get_lock():
count.value = i
if __name__ == '__main__':
TestApp().run()