[英]How do I get user input in python (Kivy framework)
I am trying to make a software in python (Kivy framework), my software will be capable of testing how strong are wifi passwords.我正在尝试在 python(Kivy 框架)中制作软件,我的软件将能够测试 wifi 密码的强度。
I have encountered a issue.我遇到了一个问题。 How do I get the user input in my.kv (kivy) file to my.py (python) file?
如何将 my.kv (kivy) 文件中的用户输入获取到 my.py (python) 文件?
.PY FILE : .PY 文件:
from kivy.app import App
from kivy.properties import StringProperty
from kivy.uix.floatlayout import FloatLayout
try:
from wifidroid.wifi import WifiManager
except:
pass
from kivy.uix.textinput import TextInput
import kivymd, kivy
try:
import wifidroid
except:
pass
from kivy.uix.label import Label
from kivy.uix.button import Button
text = 'testttt'
try:
wifi = WifiManager()
wifi.startScan()
wifi.EnabledWifi(True)
for i in range(wifi.ScanResults.size()):
ssid = [wifi.ScanResults.get(i).SSID]
bssid = [wifi.ScanResults.get(i).BSSID]
levell = [wifi.ScanResults.get(i).level]
text += ssid[0] + " " + bssid[0] + " " + str(levell[0])
except:
pass
try:
wifi.ConnectWifiWpa("WifiName", "WifiPassword")
except:
pass
#wifi.ConnectWifiWep("WifiName", "WifiPassword")
#wifi.ConnectWifiPublic("WifiName")
class Layout_For_App(FloatLayout):
output = StringProperty()
input = StringProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.ids.label_output.text = text
self.output = text
pass
class AndrdWifiApp(App):
def build(self):
return Layout_For_App()
AndrdWifiApp().run()
.KV FILE : .KV 文件:
<Layout_For_App>:
Label:
text: 'Developed By Anonymous'
pos_hint: {"x":0,"y":0.45}
Label:
text: 'OUTPUT' + root.output
id: label_output
background_color: (1, 1, 1, 1)
size_hint: (0.451, 0.7)
pos_hint: {"x":0.27,"y":0.17}
valign: "middle"
halign: "left"
color: (0,1,0)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
border: 3, 3
Button:
text: 'CRACK'
background_color: 1, 0, 0, 1
color: 0, 1, 1
size_hint: (0.4, 0.15)
pos_hint: {"x":0.0199,"y":0.01}
font_size: 30
TextInput:
text: 'Enter Wifi SSID'
id: input_value
size_hint: (0.5, 0.15)
pos_hint: {'x':0.49,'y':0.01}
font_size: 40
I want to get the user input from my .KV file, then store it in a VARIABLE in my .PY file我想从我的.KV文件中获取用户输入,然后将其存储在我的.PY文件中的VARIABLE中
This picture explains more, and it also displays how my GUI software looks like.这张图解释了更多,它还显示了我的 GUI 软件的样子。
In your Layout_For_App
class you can add a method something like:在您的
Layout_For_App
class 中,您可以添加如下方法:
def get_ssid(self):
self.ssid = self.ids.input_value.text # store the input in a variable
And using your Button
in the kv
as an example, you can trigger that method whenever the Button
is pressed:并以
kv
中的Button
为例,您可以在按下Button
时触发该方法:
Button:
text: 'CRACK'
background_color: 1, 0, 0, 1
color: 0, 1, 1
size_hint: (0.4, 0.15)
pos_hint: {"x":0.0199,"y":0.01}
font_size: 30
on_press: root.get_ssid() # trigger the storage of user input.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.