0
Q:

how to make a button in python

from tkinter import *
def example():
	print("Example")
root = Tk()
clickMe = Button(root, text="Click Me", command=example)
#Would Print "Example" In The CL
6
from tkinter import *
master = Tk()
def close_window():
    exit()
button = Button(master, text = 'Click me', command = close_window)
button.pack()
mainloop()
1
from tkinter import *
#Creating a win
win = Tk()
#Giving a Function To The Button
def btn1():
  print("I Don't Know Your Name")
#Creating The Button
button1 =  Button(win, text="Click Me To Print SomeThing", command=btn1)
#put on screen
button1.pack()
win.mainloop()
#NB:This programme Will Print Something In The Terminal
#Check My Profile To See How We Print On The Screen Or Type In Google "Tkinter Label"
1
import tkinter as tk
    

def write_slogan():
    print("Tkinter is easy to use!")

root = tk.Tk()
frame = tk.Frame(root)
frame.pack()

button = tk.Button(frame, 
                   text="QUIT", 
                   fg="red",
                   command=quit)
button.pack(side=tk.LEFT)
slogan = tk.Button(frame,
                   text="Hello",
                   command=write_slogan)
slogan.pack(side=tk.LEFT)

root.mainloop()
0
import tkinter
button1 = ttk.Button(self, text="anything", command=random command)
        button1.pack()
1
import Tkinter
import tkMessageBox

top = Tkinter.Tk()

def helloCallBack():
   tkMessageBox.showinfo( "Hello Python", "Hello World")

B = Tkinter.Button(top, text ="Hello", command = helloCallBack)

B.pack()
top.mainloop()
-1
from tkinter import *

wow = Tk()

def ree(hi):
  print(hi)
  
w = Button ( master=wow, command=ree('hi'), text="hi" )

Output:
  Tkinter:
    ______
   [  hi  ] <--- Button
    ------
  
  Shell:
    hi <--- on button pressed
-1
from tkinter import *


master = Tk()

#program you want the button to execute
def closewindow():
    exit()

#set up button
button = Button(master, text="close window", command=closewindow)

button.pack()

mainloop()
-1

New to Communities?

Join the community