How to make a window with buttons in python

后端 未结 6 1284
挽巷
挽巷 2021-02-04 16:50

How do I create a function that makes a window with two buttons, where each button has a specified string and, if clicked on, returns a specified variable? Similar to @ 3:05 in

6条回答
  •  长发绾君心
    2021-02-04 17:33

    #Creating a GUI for entering name
    def xyz():
        global a
        print a.get() 
    from Tkinter import *
    root=Tk()  #It is just a holder
    Label(root,text="ENter your name").grid(row=0,column=0) #Creating label
    a=Entry(root)           #creating entry box
    a.grid(row=7,column=8)
    Button(root,text="OK",command=xyz).grid(row=1,column=1)
    root.mainloop()           #important for closing th root=Tk()
    

    This is the basic one.

提交回复
热议问题