奇异果[按下按钮后冻结]

时间:2019-03-15 09:31:23

标签: python kivy

所以我正在尝试学习简单的Kivy GUI来发送我之前已经制作过的类的SMS,它可以正常工作,除了窗口冻结了几秒钟,有关如何使按钮按下平滑且完全不冻结的任何提示?请记住,下面的代码仅仅是应用程序的开始,只是为了确保它真正起作用。预先感谢。

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.uix.progressbar import ProgressBar
from kivy.config import Config

from sms_funksjon import SendSMS


Config.set('graphics', 'resizable', '0')  # 0 being off 1 being on as in true/false
Config.set('graphics', 'width', '500')
Config.set('graphics', 'height', '200')


class MyGrid(GridLayout):

    def __init__(self, **kwargs):
        super(MyGrid, self).__init__(**kwargs)

        self.cols = 1

        self.inside = GridLayout()
        self.inside.cols = 2

        self.inside.add_widget(Label(text="Mobil nummer: "), pow(50, 50))
        self.mobile_number = TextInput(multiline=False)
        self.inside.add_widget(self.mobile_number)

        self.inside.add_widget(Label(text="Tekst: "))
        self.tekst = TextInput(multiline=False)
        self.inside.add_widget(self.tekst)
        self.add_widget(self.inside)

        self.pb = ProgressBar(max=100)
        self.pb.value = 0
        self.add_widget(self.pb)

        self.submit = Button(text="Send", font_size=40)
        self.submit.bind(on_press=self.pressed)
        self.add_widget(self.submit)

    def pressed(self, instance):
        nummer = str(self.mobile_number.text)
        tekst = str(self.tekst.text)
        SendSMS(nummer, tekst)
        self.clear_everything()

    def clear_everything(self):
        self.mobile_number.text = ""
        self.tekst.text = ""


class Main(App):
    def build(self):
        return MyGrid()


Main().run()

0 个答案:

没有答案