I am using Python Tkinter, I have Input text box and OK Button. Now I have implemented the Button logic like, If User Input = 1, after pressing OK Button, it will open new window. Now for same implementation, Instead of pressing OK Button,I want to enter "Enter key" from Keyboard and open new window.
I do not know how to proceed.
from Tkinter import *
def UserInput():
global UI_MainForm
UI_MainForm = Tk()
UI_MainForm.resizable(1,0)
UI_MainForm.geometry("300x450+0+0")
UI_MainForm.title("ChCM 1.25 Diagnostics Main Menu")
# LabelFrame to add all the Menu menu Display items
labelframe = LabelFrame(UI_MainForm,text="Please select the below options:",width=300, height=100,bd = 2)
labelframe.pack(fill="both")
labelframe.config(relief=RIDGE)
# LabelFrame to add the User input text box and buttons
labelframe1 = LabelFrame(UI_MainForm,text="User Input:",width=300, height=100,bd = 2)
labelframe1.pack(pady=8,fill="both")
labelframe1.config(relief=FLAT)
#Entry the text and display
global entrytext
entrytext = StringVar()
entry = Entry(labelframe1,textvariable=entrytext,width=35)
entry.pack(padx = 1, pady = 5)
MainMenuDisplay = [{"ID": 1,"Description": "Display Data1"},
{"ID": 2,"Description": "Display Data2"}]
for menu in MainMenuDisplay:
temp_text = '{0}. {1}'.format(menu['ID'], menu['Description'])
Label(labelframe, text=temp_text).pack(anchor = W)
ButtonOK = Button(labelframe1, text = "OK", command =OnButtonOK, width =15)
ButtonOK.pack(side = LEFT, padx = 15, pady = 15)
UI_MainForm.mainloop()
return;
def OnButtonOK():
UI_MainForm.withdraw()
Input = int(entrytext.get())
if (Input == 1):
Data1_Menu_Display();
elif (Input == 2):
Data2_Menu_Display();
else:
print "The Input is not valid"
return;
def Data1_Menu_Display():
# self.withdraw()
global top
top = Toplevel(UI_MainForm)
top.geometry("300x450+0+0")
top.title("Display Data1")
return;
def Data2_Menu_Display():
# self.withdraw()
global top
top = Toplevel(UI_MainForm)
top.geometry("300x450+0+0")
top.title("Display Data1")
return;
def Main():
UserInput()
Main()
<Return>event to yourootwidget. More here! - CommonSense