python - Kivy exe 文件显示一个空白的灰色画布
问题描述
我只得到一个灰色的窗口。早些时候我的应用程序由于未找到窗口错误而崩溃。我用了这个线程。它修复了该错误,现在我留下了一个灰色窗口。
我的代码(抱歉有点乱)
from kivy.app import App
from kivy.core import text
from kivy.uix.widget import Widget
#from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
from kivy.metrics import dp
from kivy.uix.gridlayout import GridLayout
from utils import Main
from kivy.uix.scrollview import ScrollView
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.popup import Popup
from kivy.factory import Factory
from unipath import Path
from datetime import datetime
from kivy.lang import Builder
'''
'''
my_label = ''
Window.clearcolor = (150/255,150/255,150/255,1)
class MainWG(Widget):
def __init__(self, **kwargs):
super().__init__(**kwargs)
#Window.clearcolor = (150/255,150/255,150/255,1)
def sttwav(self, filename):
self.ids.label_update.text = 'Processing the file.....\nPlease wait....'
print('Add started' + filename[0])
#pop()
p = Path(filename[0])
np = str(p.parent)
print(my_label)
dt = datetime.now()
d = dt.strftime(("%Y-%m-%d %H-%M"))
with open(np + '\output' + d+'.txt', 'w') as f:
f.write(my_label)
f.close
self.ids.label_update.text = 'Transcript saved at '+ np + '\output'+d+'.txt\nRestart to transcribe another file'
print('file created ')
def sttmp3(self, filename):
self.ids.label_update.text = 'Processing the file.....\nPlease wait....'
print('Add started' + filename[0])
global my_label
#pop()
p = Path(filename[0])
np = str(p.parent)
print(my_label)
dt = datetime.now()
d = dt.strftime(("%Y-%m-%d %H-%M"))
#self.ids.update_label.text = 'Some error occured'
with open(np + '\output' + d+'.txt', 'w') as f:
f.write(my_label)
f.close
print('file created ')
self.ids.label_update.text = 'Transcript saved at '+ np + '\output'+d+'.txt\nRestart to transcribe another file'
print(my_label)
#self.ids.update_label.text = 'Some error occured'
#make a pop up class then call it using factory/norml
class Gridlayout(GridLayout):
def selected(self, filename):
address = filename[0]
print(address + '0')
class Scroll(ScrollView):
pass
class MyPopup(Popup):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.ids.update_label.text = my_label
def pop():
Factory.MyPopup().open()
#self.ids.my_popup.ids.scr.ids.update_label.text = my_label
#self.app.ids.update_label.text = my_label
#print(my_label)
#self.ids.update_label.text = 'Some error occured'
class MainApp(App):
pass
if __name__ == '__main__':
MainApp().run()
基维代码
Gridlayout:
<MainWG>:
Button:
text: 'Start (for mp3 files)'
size: (150, 100)
size_hint: None, None
#pos_hint: { "x" : 0 , "top" : 1 }
pos: ('850dp','400dp')
background_color: 0,1,0,1
on_press: root.sttmp3(app.root.ids.filechooser.selection)
Button:
text: 'Start (for wav files)'
size: (150, 100)
size_hint: None, None
pos: ('850dp','280dp')
background_color: 0,1,0,1
on_press: root.sttwav(app.root.ids.filechooser.selection)
Label:
text: 'Select file from file explorer in left'
pos: ('900dp','500dp')
#pos_hint: { "right" : 0.7 , "y" : 0.7 }
size_hint: None, None
Label:
id: label_update
text: 'Please wait....\nAfter clicking start button'
pos: ('870dp','200dp')
<Gridlayout>:
cols: 2
id: my_widget
FileChooserIconView:
id: filechooser
on_selection: my_widget.selected(filechooser.selection)
MainWG
我已经使用 pyinstaller 来制作它的 exe 文件。请帮忙。如果我将 Builder 放置为使用 .kv 文件,那么它会引发错误。我认为它没有使用我主要使用过的 kivy 文件
解决方案
推荐阅读
- sql - 将 VARCHAR 转换为 XML,包括 < (<) , > (>)
- php - Laravel 中的 MethodNotAllowedHttpException,Request::isMethod('') 不起作用
- javascript - 使用数组将动态添加的 li 和 ul 元素保存到数据库
- python - 使用多处理写入多个文件。错误:“TypeError:无法序列化 '_io.TextIOWrapper' 对象”
- docker - 如何设置 docker date 并确保它不与我的系统时间同步?
- python - How to construct regex to identify dollar ($) money sum
- r - 与 R 的网络定制作斗争
- javascript - ag-grid 复制并粘贴带有双引号的单元格
- bash - 访问 SGE 作业脚本标题中设置的变量
- angular - 必须在索引处为表单控件提供一个值:1 - 错误