How to make a window with buttons in python

后端 未结 6 1112
挽巷
挽巷 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:14

    Here is my method, to create a window with a button called "Hello!" and when that is closed, a new window opens with "Cool!"

    from tkinter import *
    def hello(event):
        print("Single Click, Button-l") 
    def Cool(event):                           
        print("That's cool!")
    
    widget = Button(None, text='Hello!')
    widget.pack()
    widget.bind('', Hello)
    widget.mainloop()
    
    widget = Button(None, text='Cool!')
    widget.pack()
    widget.bind('', Cool)
    

提交回复
热议问题