Answers for "tkinter button options"

13

Function to a button in tkinter

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"
Posted by: Guest on April-21-2020
2

create button tkinter

import tkinter as tk #We will use tkinter

font = 'Helvetica' #This is the font that we will use

def cmd(): #This is the command for our button
  label = tk.Label(master,text="Hi to everyone",font=(font,16)) #We'll create
  																#a label
  label.grid(row=1,column=0,sticky='w') #This is the 'grid'

class main: #Our main class
  def __init__(self,master):
    master.title('Simple Interface') #The title of our interface
    master.geometry('500x500+0+0') #Position and Size of master
    button = tk.Button(master,text='Ok',command=cmd) #Creating the button
    button.grid(row=0,column=0,sticky='w') #Grid of the button

if __name__ == '__main__':
  master = tk.Tk() #Now we're creating the window
  main = main(master)
  master.mainloop #Mainloop of master (the window)
Posted by: Guest on July-26-2021
4

python button tkinter

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
Posted by: Guest on March-20-2020
0

add button python

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()
Posted by: Guest on July-06-2020
1

button tkinter

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()
Posted by: Guest on May-30-2020

Python Answers by Framework

Browse Popular Code Answers by Language