I've managed to call the encrypt function from the Encrypt class, I've referenced the ids from kv file now i want to print the result of the function on the label
.py file
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager
from kivy.factory import Factory
from kivy.animation import Animation
import string
from kivy.properties import ObjectProperty
from kivy.core.window import Window
from kivymd.uix.label import Label
from kivy.uix.scrollview import ScrollView
Window.size = (360, 600)
alphabet = string.ascii_lowercase
class CryptoMD(MDApp):
def __init__(self, **kwargs):
self.Encrypt = Encrypt()
self.title = 'Crypto'
self.sm = ScreenManager()
super().__init__(**kwargs)
def animate_card(self, widget):
anim = Animation(pos_hint={"center_y": 0.6}, duration=1)
anim.start(widget)
def animate_background(self, widget):
anim = Animation(size_hint_y=1) + Animation(size_hint_y=0.5, duration=0.5)
anim.start(widget.ids.bx)
def set_text(self, Text, key):
Text = Text.lower()
key = key
Key = int(key)
obj = Encrypt()
out_encrypt = obj.encrypt(Text,key)
# self.root.ids.output.text = out_encrypt
self.root.ids.output.text = out_encrypt
adding above line in def set_text(self, Text, key): should do it but it shows an error message
ValueError: None is not allowed for MDLabel._text
class Encrypt():
def encrypt(self, Text, key):
Text = Text.lower()
key = key
Key = int(key)
encrypted_message = ""
for c in Text:
if c in alphabet:
position = alphabet.find(c)
new_position = (position + Key) % 26
new_character = alphabet[new_position]
encrypted_message += new_character
else:
encrypted_message += c
message = str(encrypted_message)
print(message.upper())
def decrypt(self, Text, key):
Text = Text.lower()
key = key
Key = int(key)
encrypted_message = ""
for c in Text:
if c in alphabet:
position = alphabet.find(c)
new_position = (position - Key) % 26
new_character = alphabet[new_position]
encrypted_message += new_character
else:
encrypted_message += c
message = str(encrypted_message)
print(message.upper())
if __name__ == '__main__':
CryptoMD().run()
.kv file
#:kivy 1.11.1
#:import rgba kivy.utils.rgba
<Special@Screen>:
BoxLayout:
#Special:
# id: special_gridlayout
MDCard:
id:card
orientation: 'vertical'
size_hint: [0.7, 0.8]
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
padding: [20, 10, 10, 20]
spacing: 7
BoxLayout:
padding: [10, 10, 10, 10]
orientation: 'vertical'
MDLabel:
text: "[color=000000] Caesar Cipher [/color]"
text_size: self.size
font_size: 35
bold: True
markup: True
halign: "center"
valign: "top"
MDLabel:
id: output
text: "[color=000000] Output [/color]"
text_size: self.size
font_size: 35
bold: True
markup: True
halign: "center"
valign: "top"
MDTextField:
id: Text
text: "A"
auto_indent: True
allow_copy: True
multiline: False
helper_text: "Enter Text..."
helper_text_mode: "persistent"
required: True
MDTextField:
id: key
text: "1"
input_filter: "int"
helper_text: "Enter Key..."
helper_text_mode: "persistent"
required: True
MDRoundFlatButton:
id: encrypt_bt
text: "Encrypt"
size_hint_x: 0.6
pos_hint: {'center_x': 0.5}
on_press:
app.set_text(Text.text, key.text)
MDRoundFlatButton:
id: decrypt_bt
text: "Decrypt"
size_hint_x: 0.6
pos_hint: {'center_x': 0.5}
on_press:
app.Encrypt.decrypt(Text.text, key.text) if Text.text != "" else None
<BackgroundLayer@BoxLayout>:
orientation: 'vertical'
BoxLayout:
id: bx
orientation: 'vertical'
size_hint_y: 0.1
canvas.before:
Color:
rgba: rgba('#8A2BE2')
RoundedRectangle:
pos: self.pos
size: self.size
radius: [0, 0, 40, 40]