我在Python 3.7,Ubuntu 20.04上使用Kivy 1.11.1。
运行程序时,我的代码显示一个窗口,但是该窗口是完全黑色的,并且不响应任何输入。 我的代码是这样的:
import kivy
kivy.require('1.11.1')
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.core.window import Window
Window.clearcolor = (0.3961, 0.4627, 0.8, 1)
class LoginScreen(GridLayout):
def btn1Click(self, instance):
print('The button was clicked')
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.cols = 2
self.button1 = Button(text='Click Me', font_size=14)
self.button1.bind(on_press=self.btn1Click)
self.add_widget(self.button1)
self.add_widget(TextInput())
class CreateMachineProgram(App):
def build(self):
return LoginScreen()
if __name__ == '__main__':
CreateMachineProgram().run()
当我在行self.add_widget(TextInput())
上注释时,突然我的代码正确加载了。我在做什么错了?