0

I want to code a short programme. My idea was to code a login window. Then the next window opens and then I should be able to encrypt a text I wrote into a ScrolledText. The whole encryption should be done with the ceasar principal. I combined my code(at the bottom) with this one:

def caesar(text, schluessel):
    geheim = ''
    for i in text:
        number = ord(i) + schluessel   #122 = 119+3
        if number > 122:
            number -= 26
        elif number == 32 + schluessel: #whitespace
            number = 32
        letter = chr(number)
        geheim += letter
    print(geheim)

I recieved this error message:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
  File "C:/Users/pc/PycharmProjects/test_22_11_22/main.py", line 77, in caesar
    for i in encryptiontextentry:
  File "C:\Program Files\Python38\lib\tkinter\__init__.py", line 1643, in cget
    return self.tk.call(self._w, 'cget', '-' + key)
TypeError: can only concatenate str (not "int") to str

This is my code:

from tkinter import *
from tkinter.scrolledtext import ScrolledText




class Login:
    def __init__(self):
        self.user ={'1':'1'}
        self.loginwindow = Tk()
        self.loginwindow.geometry("500x300")
        self.loginwindow.resizable(width= False, height= False)


        self.loginlabel = Label(text="Login",font= ("arial",50))
        self.loginausgabe = Label(self.loginwindow)
        self.loginusernamelabel = Label(self.loginwindow, text="Username",font= ("arial",12))
        self.loginusernameentry = Entry(self.loginwindow,font= ("arial",12))
        self.loginpasswordlabel = Label(self.loginwindow,text="Password",font= ("arial",12))
        self.loginpasswordentry = Entry(self.loginwindow,font= ("arial",12), show="*")
        self.loginbtn = Button(self.loginwindow,text="login",width= 38, command=self.login)


        self.loginlabel.place(x="140",y="0")
        self.loginausgabe.place(x="140",y="140")
        self.loginusernamelabel.place(x="140",y ="80")
        self.loginusernameentry.place(x="230",y="80")
        self.loginpasswordlabel.place(x="140",y ="100")
        self.loginpasswordentry.place(x="230",y="100")
        self.loginbtn.place(x="140",y="120")
        self.loginwindow.mainloop()


    def login(self):
        loginusernameentry = self.loginusernameentry.get()
        if loginusernameentry in self.user.keys():
            if self.loginpasswordentry.get() == self.user[loginusernameentry]:
                self.loginausgabe.config(text="Welcome!")
                self.encryption()
            else: self.loginausgabe.config(text="Invalid password!")
        else: self.loginausgabe.config(text="Unknown User!")
        self.loginusernameentry.config(text="")
        self.loginusernameentry.config(text="")

    def encryption(self):
        self.loginwindow.destroy()
        self.encryptionwindow = Tk()
        self.encryptionwindow.geometry("1000x600")
        self.encryptionwindow.resizable(width= False, height= False)

        self.encryptiontextlabel = Label(self.encryptionwindow,text="encryption text",font= ("arial",12))
        self.encryptiontextentry = ScrolledText(self.encryptionwindow)
        self.decryptiontextlabel = Label(self.encryptionwindow,text="dencryption text",font= ("arial",12))
        self.decryptiontextentry = ScrolledText(self.encryptionwindow)
        self.encryptionbtn = Button(self.encryptionwindow,text="encrypt",command=self.caesar)
        self.caesarkeyencryption = Entry(self.encryptionwindow,width="2")
        self.decryptionbtn = Button(self.encryptionwindow,text="decrypt",command=self.caesar)
        self.caesarkeydecryption = Entry(self.encryptionwindow,width="2")

        self.decryptiontextlabel.place(x="120", y="310")
        self.decryptiontextentry.place(x="120", y="330", width="800",height="200")
        self.encryptiontextlabel.place(x="120", y="40")
        self.encryptiontextentry.place(x="120", y="60", width="800",height="200")
        self.encryptionbtn.place(x="120",y="260")
        self.caesarkeyencryption.place(x="170",y="264")
        self.decryptionbtn.place(x="120",y="530")
        self.caesarkeydecryption.place(x="170",y="534")


        self.encryptionwindow.mainloop()

   ** def caesar(self):
        caesarkeyencryption = int(self.caesarkeyencryption.get())
        encryptiontextentry = self.encryptiontextentry
        print(caesarkeyencryption)
        encryptiontextresult = ''
        for i in encryptiontextentry:
            number = ord(i) + caesarkeyencryption
            if number > 122:
                number -= 26
            elif number == 32 + caesarkeyencryption: #whitespace
                number = 32
            letter = chr(number)
            encryptiontextresult += letter
        print(encryptiontextresult)

**


l = Login()

John Coleman
  • 51,337
  • 7
  • 54
  • 119
Wili44
  • 1
  • 2
  • Does this answer your question? [String concatenate TypeError: can only concatenate str (not "int") to str"](https://stackoverflow.com/questions/53465931/string-concatenate-typeerror-can-only-concatenate-str-not-int-to-str) – picobit Nov 23 '22 at 23:51

0 Answers0