when I try to run the code it just displays a blank screen I tried to find answers everywhere but nothing works This is my main.py file:
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.graphics import *
from kivy.lang import *
from kivy.uix.screenmanager import *
class MyWidgets(Widget):
pass
kv = Builder.load_file('math.kv')
class Calculator(App):
def build(self):
return kv
if __name__ == '__main__':
Calculator().run()
And this is my math.kv file:
<MyWidgets>
num: num
GridLayout:
cols: 1
TextInput:
id: num
multiline: False
GridLayout:
cols: 3
Button:
text: '1'
font_size: 25
Button:
text: '2'
font_size: 25
Button:
text: '3'
font_size: 25
Looks like you have an indent error in build
function. Still, that should have shown some error instead of showing a blank screen. Then in your .kv
file, I don't know what that num
is. After removing num
from .kv
and correcting indentation error I run the file and it works fine. Here's the code I used:
.py
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.graphics import *
from kivy.lang import *
from kivy.uix.screenmanager import *
class MyWidgets(Widget):
pass
class Calculator(App):
def build(self):
kv = Builder.load_file('math.kv')
return kv
if __name__ == '__main__':
Calculator().run()
.kv
<MyWidgets>
GridLayout:
cols: 1
TextInput:
id: num
multiline: False
GridLayout:
cols: 3
Button:
text: '1'
font_size: 25
Button:
text: '2'
font_size: 25
Button:
text: '3'
font_size: 25
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.