我正在尝试创建一个简单的首字母缩写词定义 GUI。我大部分都拥有它。我的目标是实现两种不同类型的输出。如果用户输入 AI 希望它输出所有以 A 开头的首字母缩写词,就会发生这种情况。例如,当我键入 ACL 时,它会再次带回所有首字母缩写词,而不仅仅是 ACL 首字母缩写词。我怀疑错误或非错误可能来自 .join
from tkinter import *
import tkinter.messagebox
HEIGHT = 400
WIDTH = 700
root = Tk()
root.title("Testing")
a_canvas = Canvas(root, height=HEIGHT, width=WIDTH)
a_canvas.pack()
def clicked():
entered = a_entry.get()
a_textbox.delete(0.0, END)
try:
textin = ", ".join(loop_over_input(entered))
except:
textin = 'Sorry invalid information provided.\nResubmit with the correct information.\n'
a_textbox.insert(0.0, textin)
def clr():
a_entry.delete(0, 'end')
a_textbox.delete(0.0, 'end')
# def gone():
# tkinter.messagebox.showinfo("Goodbye", 'Come back soon.')
# exit()
# Keep this is the master code
def loop_over_input(the_str=''):
master_list = []
for char in the_str:
tmp_char = passwordConversion[char]
master_list.append(tmp_char)
print("Master Pass List: ", master_list)
return master_list
def cont():
tkinter.messagebox.showinfo("About",
'\n Wrote by Me \n Version 1.0 \n Python\Tkinter')
# Custom Dictionary
passwordConversion = {
"A": "AWS - Amazon Web Services \nAmazon ES - Amazon Elasticsearch Service \nAMI - Amazon Machine Image \nAPI - Application Programming Interface \nAI - Artificial Intelligence \nACL - Access Control List \nARN - Amazon Resource Name \nAZ - Availability Zone \nASG - Auto Scaling Group \nAES - Advanced Encryption System \nADFS - Active Directory Federation Service",
"AWS": "Amazon Web Services",
"Amazon ES": "Amazon Elasticsearch Service",
"AMI": "Amazon Machine Image",
"API": "Application Programming Interface",
"AI": "Artificial Intelligence",
"ACL": "Access Control List",
"ARN": "Amazon Resource Name",
"AZ": "Availability Zone",
"ASG": "Auto Scaling Group",
"AES": "Advanced Encryption System",
"ADFS": "Active Directory Federation Service",
}
# Creating the Frames
a_frame = Frame(root, bg='Red', bd=5)
a_frame.place(relx=0.5, rely=0.1, relwidth=0.75, relheight=0.1, anchor='n')
a_middle_frame = Frame(root, bg='White')
a_middle_frame.place(relx=0.5, rely=0.25, relwidth=0.75, relheight=0.25, anchor='n')
# Creating entry boxes
a_entry_var = StringVar()
a_entry = Entry(a_frame, font=20, textvariable=a_entry_var)
a_entry.place(relwidth=0.65, relheight=1)
# Create a text box
a_textbox = Text(a_middle_frame, font=12)
a_textbox.place(relwidth=1.00, relheight=1)
# Creating button
a_button = Button(a_frame, padx=2, pady=2, text='Get Defination', command=clicked, bg='Silver', font=('Calibri 11 bold'))
a_button.place(relx=0.7, relheight=1, relwidth=0.3)
a_buttons_frame = Frame(root)
a_buttons_frame.place(relx=0.4, rely=0.6)
a_button2 = Button(a_buttons_frame, padx=2, pady=2, text='Clear Fields', font=('Calibri 11 bold'), bg='Silver', command=clr)
a_button2.grid(column=0, row=0, padx=(20, 20))
# a_button3 = Button(a_buttons_frame, padx=2, pady=2, text='Exit', command=gone, bg='Silver', font=('none 18 bold'))
# a_button3.grid(column=1, row=0, padx=(20, 0))
a_label = Label(text="- For Me Only - \n- Contains information for me only", )
a_label.pack(side='bottom')
# Define Menu Items
my_menu = Menu(root)
root.config(menu=my_menu)
# Create Menu Items
file_menu = Menu(my_menu)
my_menu.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="Exit", command=root.quit)
# Create another submenu Edit
edit_menu = Menu(my_menu)
my_menu.add_command(label="About", command=cont)
root.mainloop()