简体   繁体   English

如何将 output 放入 tkinter 输入字段

[英]How do I get a output into a tkinter Entry field

Im making my own cypher encryption and I want to put the result into the entry field called output.我正在制作自己的 cypher 加密,我想将结果放入名为 output 的输入字段中。 Now im just using print() so I could test if I got a result.现在我只是使用 print() 所以我可以测试我是否得到了结果。 But that was only for testing.但这只是为了测试。 This is one of the first times I used Python so if there are some other things I could have done better please let me know:) this is what I have so far.这是我第一次使用 Python,所以如果还有其他一些我可以做得更好的事情,请告诉我:) 这就是我到目前为止所拥有的。

from tkinter import *

#Make frame
root = Tk()
root.geometry("500x300")
root.title("Encryption Tool")

top_frame = Frame(root)
bottom_frame = Frame(root)

top_frame.pack()
bottom_frame.pack()

#Text
headline = Label(top_frame, text="Encryption Tool", fg='black')
headline.config(font=('Courier', 27))
headline.grid(padx=10, pady=10)

Key = Label(bottom_frame, text="Key:", fg='black')
Key.config(font=('Courier', 20))
Key.grid(row=1)

Text_entry = Label(bottom_frame, text="Text:", fg='black')
Text_entry.config(font=('Courier', 20))
Text_entry.grid(row=2)

Output_text = Label(bottom_frame, text="Output:", fg='black')
Output_text.config(font=('Courier', 20))
Output_text.grid(row=3)

Key_entry = Entry(bottom_frame)
Key_entry.grid(row=1, column=1)

Text_entry = Entry(bottom_frame)
Text_entry.grid(row=2, column=1)

Output_text = Entry(bottom_frame)
Output_text.grid(row=3, column=1)

#Encryption_button

def encrypt():
    result = ''
    text = ''

    key = Key_entry.get()
    text = Text_entry.get()
    formule = int(key)

    for i in range(0, len(text)):
            result = result + chr(ord(text[i]) + formule + i * i)


    result = ''                                     

Encryption_button = Button(bottom_frame, text="Encrypt", fg='black')
Encryption_button.config(height = 2, width = 15)
Encryption_button.grid(row = 4, column = 0, sticky = S)
Encryption_button['command'] = encrypt


#Decryption_button

def decrypt():
    result = ''
    text = ''

    key = Key_entry.get()
    text = Text_entry.get()
    formule = int(key)

    for i in range(0, len(text)):
            result = result + chr(ord(text[i]) - formule - i * i)

    print(result)
    result = ''

Decryption_button = Button(bottom_frame, text="Decrypt", fg="black")
Decryption_button.config(height = 2, width = 15)
Decryption_button.grid(row = 5, column = 0, sticky = S)
Decryption_button['command'] = decrypt

#Quit_button
def end():
    exit()

Quit_button = Button(bottom_frame, text="Quit", fg='black')
Quit_button.config(height = 2, width = 15)
Quit_button.grid(row = 6, column = 0, sticky = S)

Quit_button['command'] = end

root.mainloop()

The most common way to do this with tkinter would be with a StringVar() object you can connect to the Entry object (Some documentation here).使用 tkinter 执行此操作的最常见方法是使用 StringVar() object 您可以连接到条目 object(此处的一些文档)。

output_entry_value = StringVar()

Output_text = Entry(bottom_frame, textvariable=output_entry_value)
Output_text.grid(row=3, column=1)

then you can.set() the result in the stringvar, and it will update in the entries you connected it to:然后你可以.set() 字符串变量中的结果,它会在你连接到的条目中更新:

output_entry_value.set(result)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用tkinter for python中的迭代创建输入字段和按钮以从输入字段获取内容? - how do I create entry fields and buttons to get the content from the entry field using iteration in tkinter for python? 在 tkinter 中,我如何将数字输入到条目中 - in tkinter how do i get a number into an entry 当输入字段为空并单击翻译按钮时,如何使 output 字段在 Tkinter 中不返回任何内容? - When the entry field is empty, and I click the translate button, how do I make the output field return nothing in Tkinter? 如何在 tkinter 中使用 Entry.get() function? - How do I use the Entry.get() function in tkinter? 如何制作Tkinter条目小部件? - How do I make a tkinter entry widget? 如何在条目和 output 小部件中启用右键单击以分别在 Tkinter 中粘贴和复制? - How do I enable right click in entry and output widget for pasting and copying respectively in Tkinter? 如何通过按下按钮从 tkinter 输入字段返回变量以在另一个 function 中使用? - How do I return a variable from a tkinter Entry field to use in another function by pressing a button? 如何获取tkinter的输出以打印到GUI而不是CLI中? - How do i get the output of tkinter to print into GUI instead of CLI? 如何从 tkinter 中的条目中获取字符串? 我使用.get(),但它只返回0 - How do i get string from Entry in tkinter? I use .get(), but it only returns 0 如何获得Tkinter入门? - How to get Tkinter entry?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM