Answers for "multiple buttons tkinter"

6

tkinter give button 2 commands

button = Button(root, text="test", command=lambda:[funct1(),funct2()])
Posted by: Guest on March-22-2020
1

multiple functions tkinter

command=lambda:[funcA(), funcB(), funcC()]
Posted by: Guest on August-11-2020
2

how to create multiple windows in tkinter with button

#import module needed
import tkinter as tk
#write the new window function which
#will be called when button pressed
def new_window():
    window = tk.Toplevel(root)
    canvas = tk.Canvas(window, height=HEIGHT, width=WIDTH)
    canvas.pack()

HEIGHT = 400
WIDTH = 300
#create original window (title not need but why not?)
root = tk.Tk()
root.title("new window making machine: ")
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()
#create button that will be placed
button = tk.Button(root, text="new window", bg='black', fg='#469A00',
                              command=lambda: new_window())
#can use .grid() or .place() instead of pack .place()
#is the best according to me if you want the most control of positions
button.pack()
root.mainloop()
Posted by: Guest on April-14-2020
0

python tkinter button multiple commands

pythonCopytry:
    import Tkinter as tk
except:
    import tkinter as tk
    

class Test():
   def __init__(self):
       self.root = tk.Tk()
       self.root.geometry('200x100')
       self.button = tk.Button(self.root,
                          text = 'Click Me',
                          command = self.combineFunc(self.funcA, self.funcB, self.funcC))
       self.button.pack()

       self.labelA = tk.Label(self.root, text="A")
       self.labelB = tk.Label(self.root, text="B")
       self.labelC = tk.Label(self.root, text="C")

       self.labelA.pack()
       self.labelB.pack()
       self.labelC.pack()
       
       self.root.mainloop()

   def combineFunc(self, *funcs):
       def combinedFunc(*args, **kwargs):
            for f in funcs:
                f(*args, **kwargs)
       return combinedFunc

   def funcA(self):
       self.labelA["text"] = "A responds"

   def funcB(self):
       self.labelB["text"] = "B responds"

   def funcC(self):
       self.labelC["text"] = "C responds"
       
app = Test()
Posted by: Guest on December-14-2020

Python Answers by Framework

Browse Popular Code Answers by Language