现在,当我点击加密终端显示一个加密的消息,我只想显示在一个可滚动的文本框与能力,以复制加密的消息消息消息,我尝试了很多想法,但我不能做到这一点
这是代码,请检查一下。
加密md2.py
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 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())
class CryptoMD(MDApp):
Encrypt = ObjectProperty()
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 build(self):
self.sm.add_widget(Factory.Main())
return self.sm
if __name__ == '__main__':
CryptoMD().run()
这是cryptomd.kv
# :kivy 1.11.1
# :import rgba kivy.utils.rgba
<Main@Screen>:
name: "cryptomd"
on_enter:
app.animate_card(card)
app.animate_background(background)
BackgroundLayer:
id: background
MDCard:
id:card
orientation: 'vertical'
size_hint: [0.8, 0.7]
pos_hint: {'center_x': 0.5, 'center_y': 0}
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: 30
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
text: "Encrypt"
size_hint_x: 0.6
pos_hint: {'center_x': 0.5}
on_press:
app.Encrypt.encrypt(Text.text, key.text) if Text.text != "" else None
MDRoundFlatButton:
id: decrypt
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]
BoxLayout:
orientation: 'horizontal'
padding: [10, 10, 10, 30]
提前谢谢。。
暂无答案!
目前还没有任何答案,快来回答吧!