我已经在kivy编写了一个应用程序,但它总共有3个类,其中一个是application class
第二个是exampleroot class
,第三个是pscan calss
我想要运行
现在当我按下屏幕上的按钮....所以它应该运行pscan类....这就是我想要的...我已经给出了我的main.py和example.kv文件
MAIN.PY文件
from kivy.app import App
import socket, sys, threading, os, time
################# LIBRARIES IMPORTED ##############
#####MY FIRST CLASS NAMED pscan ######
class pscan(threading.Thread):
def __init__(self,ip, port):
threading.Thread.__init__(self)
self.ip = ip
self.port = port
def run(self):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)
s.connect((socket.gethostbyname(self.ip), int(self.port)))
print "\n[+] OPEN:",self.ip, self.port
s.close()
except:
print "\n[!] CLOSE:",self.ip, self.port
target = 'www.google.com'
sport = 1
eport= 100
############ MY SECOND CLASS NAMED EampleRoot ########
class ExampleRoot(BoxLayout):
def final(self,*args):
while sport <= eport:
work=pscan(target,sport) #run pscan class from Exampleroot class
work.start() #DID not working
time.sleep(0.1)
sport=sport+1
class ExampleApp(App):
return ExampleRoot()
if __name__ == "__main__":
ExampleApp().run()
.KV文件
<Exampleroot>
Button:
text:"PRESS ME TO RUN PSCAN CLASS"
on_press:root.final()
答案 0 :(得分:2)
你App类需要定义一个返回你的根小部件的'build'方法。这是你的代码工作,虽然我不知道它想要做什么..; - )
from kivy.app import App
import socket, sys, threading, os, time
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
<Exampleroot>:
Button:
text:"PRESS ME TO RUN PSCAN CLASS"
on_press:root.final()
''')
class pscan(threading.Thread):
def __init__(self,ip, port):
threading.Thread.__init__(self)
self.ip = ip
self.port = port
def run(self):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)
s.connect((socket.gethostbyname(self.ip), int(self.port)))
print "\n[+] OPEN:",self.ip, self.port
s.close()
except:
print "\n[!] CLOSE:",self.ip, self.port
class ExampleRoot(BoxLayout):
sport = 1
target = 'www.google.com'
eport= 100
def final(self,*args):
while self.sport <= self.eport:
work = pscan(self.target, self.sport) #run pscan class from Exampleroot class
work.start() #DID not working
time.sleep(0.1)
self.sport = self.sport + 1
class ExampleApp(App):
def build(self):
return ExampleRoot()
if __name__ == "__main__":
ExampleApp().run()