I'm starting to learn Kivy to make GUIs and all is fine, but I can't paste external text to my TextInput widgets. There is no problem with copying and pasting text internal to the kivy window (copy from a TextInput to another). The issue is that I cannot paste text external to the kivy window (copy text from say the browser and paste it into a TextInput). My OS: Kali Linux Rolling 2020.1 (Debian) Here is some of my code
class LoginPage(Screen):
keep_logged_var = BooleanProperty() # declaring some variables to use in the .kv file
school_code_var = StringProperty()
user_id_var = StringProperty()
password_var = StringProperty()
failed_var = BooleanProperty()
def __init__(self, **kwargs):
super(LoginPage, self).__init__(**kwargs)
self.keep_logged_var = keep_logged # assigning value to my variables
if self.keep_logged_var:
self.school_code_var = school_code
self.user_id_var = user_id
self.password_var = password
self.failed_var = False
def login(self, keep_logged, school_code_, user_id_, password_):
if keep_logged == 'normal': keep_logged = False
elif keep_logged == 'down': keep_logged = True
global token, school_code, user_id, password
school_code = school_code_
user_id = user_id_
password = password_
token = get_token(school_code, user_id, password)
if token == 'Failed to log in': # login failed
print('failed')
self.failed_var = True
else: # login successful
if keep_logged:
settings['keep_logged'] = True
settings['school_code'] = school_code
settings['user_id'] = user_id
settings['password'] = password
with open('settings.json', 'w') as file:
json.dump(settings, file, indent=2)
global scheda
scheda = get_schede()
and here is my kivy file
<LoginPage>:
keep_logged: root.keep_logged_var
school_code: root.school_code_var
user_id: root.user_id_var
password: root.password_var
failed: root.failed_var
name: 'loginpage' # name of the window
FloatLayout:
canvas:
Color:
rgba: 1,1,1,1
Rectangle:
size: root.width, root.height
Label: # school code label
text: 'School Code: '
font_size: 20
pos_hint: {'x': -0.15, 'y':0.2}
color: 0,0,0,1
TextInput: # school code entry
id: school_code_id
text: root.school_code if root.keep_logged else ''
multiline: False
size_hint: 0.2, 0.05
pos_hint: {'x': 0.45, 'y': 0.67}
Label: # user id label
text: 'User ID '
font_size: 20
pos_hint: {'x': -0.15, 'y': 0.1}
color: 0,0,0,1
TextInput: # user id entry
id: user_id_id
size_hint: 0.2, 0.05
pos_hint: {'x': 0.45, 'y': 0.57}
multiline: False
text: root.user_id if root.keep_logged else ''
Label: # password label
text: 'Password '
font_size: 20
pos_hint: {'x': -0.15, 'y': 0}
color: 0,0,0,1
TextInput: # password entry
id: password_id
size_hint: 0.2, 0.05
pos_hint: {'x': 0.45, 'y': 0.47}
password: True
multiline: False
text: root.password if root.keep_logged else ''
CheckBox: # keep me logged in
id: keep_logged_id
size_hint: 0.4, 0.1
background_color: 1,1,1,1
color: 0,0,0,1
pos_hint: {'x': 0.05, 'y': 0.33}
active: root.keep_logged_var
Label: # keep me logged in
text: 'Keep me logged in'
color: 0,0,0,1
font_size: 15
pos_hint: {'x': -0.14, 'y': -0.12}
Button: # login button
text: 'Login'
size_hint: 0.13, 0.06
color: 1,1,1,1
pos_hint: {'x': 0.5, 'y': 0.35}
on_press:
root.login(keep_logged_id.state, school_code_id.text, user_id_id.text, password_id.text)
Label: # failed login label
text: 'Login failed' if root.failed else ''
font_size: 20
pos_hint: {'y': -0.2}
color: 1,0,0,1
Thanks for your help
Solved:
I was missing some required modules that didn't come with my os (xclip and xsel)
after installing them sudo apt install xclip
sudo apt install xsel
I was able to copy/paste successfully from and to my kivy TextInput.