首页 > 解决方案 > 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 文件

标签: pythonkivypyinstaller

解决方案


推荐阅读