How to make a window with buttons in python

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

    tkinter is a GUI Library, this code creates simple no-text buttons:

     import tkinter as tk
     class Callback:
         def __init__(self, color):
             self.color = color
         def changeColor(self): 
             print('turn', self.color)
     c1 = Callback('blue')
     c2 = Callback('yellow')
     B1 = tk.Button(command=c1.changeColor) 
     B2 = tk.Button(command=c2.changeColor) 
     B1.pack()
     B2.pack()
    

提交回复
热议问题