所以我当时正在观看this视频,所以我一直按照他的意愿进行编码,就像他一样,我编写了代码,但是当我运行时,它没有给出错误,但是返回了黑屏,而不是计算器用户界面,另一部视频也发生了同样的事情。(请注意,我的基维版本是1.10.1)
[INFO ] [Logger ] Record log in C:\Users\Erfan\.kivy\logs\kivy_19-01-
01_23.txt
[INFO ] [Kivy ] v1.10.1
[INFO ] [Python ] v3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018,
23:09:28) [MSC v.1916 64 bit (AMD64)]
[INFO ] [Factory ] 194 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_gif
(img_pil, 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 353.62'>
[INFO ] [GL ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO ] [GL ] OpenGL renderer <b'GeForce GT 730/PCIe/SSE2'>
[INFO ] [GL ] OpenGL parsed version: 4, 5
[INFO ] [GL ] Shading version <b'4.50 NVIDIA'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not
docked
[INFO ] [Base ] Start application main loop
[INFO ] [Base ] Leaving application in progress...
这是我的代码,没有错误。
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 Label
from kivy.uix.widget import Widget
kivy.require("1.10.1")
class CalcGridLayout(GridLayout):
pass
class CalculatorApp(App):
def LoginForm(self):
return CalcGridLayout
calcApp = CalculatorApp()
calcApp.run()
它将重定向到我创建的名为“ Calculator.kv”的文件 这些是文件中的代码。
<CustButton@Button>:
font_size: 32
<CalcGridLayout>:
id: calculator
display: entry
rows: 5
padding: 10
spacing: 10
BoxLayout:
TextInput:
id: entry
font_size: 32
multiline: False
BoxLayout:
spacing: 10
CustButton:
text: "7"
on_press: entry.text += self.text
CustButton:
text: "8"
on_press: entry.text += self.text
CustButton:
text: "9"
on_press: entry.text += self.text
CustButton:
text: "+"
on_press: entry.text += self.text
BoxLayout:
spacing: 10
CustButton:
text: "4"
on_press: entry.text += self.text
CustButton:
text: "5"
on_press: entry.text += self.text
CustButton:
text: "6"
on_press: entry.text += self.text
CustButton:
text: "-"
on_press: entry.text += self.text
BoxLayout:
spacing: 10
CustButton:
text: "1"
on_press: entry.text += self.text
CustButton:
text: "2"
on_press: entry.text += self.text
CustButton:
text: "3"
on_press: entry.text += self.text
CustButton:
text: "*"
on_press: entry.text += self.text
BoxLayout:
spacing: 10
CustButton:
text: "AC"
on_press: entry.text = ""
CustButton:
text: "0"
on_press: entry.text += self.text
CustButton:
text: "="
on_press: entry.text += self.text
CustButton:
text: "/"
on_press: entry.text += self.text
答案 0 :(得分:0)
我认为您在python文件中返回CalcGridLayout后错过了括号
答案 1 :(得分:0)
是的!我发现了问题,问题是我可能使用了LoginForm,这与我们需要的完全不同,所以我基本上需要做的就是更改LoginForm来构建。
我的意思是
def LoginForm(self):
到
def build(self):