I'm just learning Python and I have the base concept down, and already a few command line programs. I'm now learning how to create GUIs with Tkinter.
I created a simple GUI to accept some user information from a Entry
widget, and then, when the user clicks submit, it should pop up a dialog.
The dialog should ask for the first name and last name.
The problem is that I don't know how to handle the event when the user clicks submit.
Here's my code:
from Tkinter import *
class GUI(Frame):
def __init__(self,master=None):
Frame.__init__(self, master)
self.grid()
self.fnameLabel = Label(master, text="First Name")
self.fnameLabel.grid()
self.fnameEntry = Entry(master)
self.fnameEntry.grid()
self.lnameLabel = Label(master, text="Last Name")
self.lnameLabel.grid()
self.lnameEntry = Entry(master)
self.lnameEntry.grid()
self.submitButton = Button(self.buttonClick, text="Submit")
self.submitButton.grid()
def buttonClick(self, event):
""" handle button click event and output text from entry area"""
pass
if __name__ == "__main__":
guiFrame = GUI()
guiFrame.mainloop()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…