Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to add button in tkinter

from tkinter import *
window = Tk()

def got_clicked():
  print("I got clicked!")

my_button = Button(text="Click me", command=got_clicked)
my_button.pack()

window.mainloop()
Comment

add a button on tkinter

import tkinter
button1 = ttk.Button(self, text="anything", command=random command)
        button1.pack()
Comment

how to create a button using tkinter

import tkinter as tk
window = tk.Tk()

button=tk.Button(window, text="CLICK ME: ", command=testCommand) 
"""creates the button and sets the location, text and what command to run once clicked"""


button.pack()
""" this loads the button in to the program.
you can use button.grid(row=1, column=1) as a another option to load this but both
cannot be used in a program together"""
window.mainloop()
Comment

add a button on tkinter


import tkinter as tk
import random


def color(ndex):
    button_label_list[ndex][1].config(bg="#%06x" % random.randint(0, 16777215))


def dump():
    global count, button_label_list
    button_label_list.append([tk.Button(frame, text="color", command=lambda x=count: color(x)),
                              tk.Label(frame, text="Color", bg="#" + ("%06x" % random.randint(0, 16777215)))])
    button_label_list[-1][0].grid(row=0, column=count, sticky='nsew')
    button_label_list[-1][1].grid(row=1, column=count, sticky='nsew')
    frame.columnconfigure(count, weight=1)
    count += 1


root = tk.Tk()
count = 0
button_label_list = []
root.title("Hello")
root.rowconfigure(1, weight=1)
root.columnconfigure(2, weight=1)

frame = tk.Frame(root)
frame.rowconfigure(1, weight=1)
frame.grid(row=0, column=2, sticky='nsew', rowspan=2)

tk.Button(root, text="butt ON", command=dump).grid(row=0, column=0, sticky='nsew')
tk.Button(root, text="Quit!", command=root.quit).grid(row=0, column=1, sticky='nsew')
tk.Label(root, text="This is a label", bg="PeachPuff").grid(row=1, column=1, columnspan=1, sticky='nsew')

root.mainloop()

Comment

PREVIOUS NEXT
Code Example
Python :: print for loop in same line python 
Python :: random.sample python 
Python :: how to convert csv to excel in python 
Python :: pandas .nlargest 
Python :: how to get a summary of a column in python 
Python :: catch error in mongo query python 
Python :: count nan values 
Python :: markers seaborn 
Python :: python split string after substring 
Python :: Copying a list using deepcopy() in python 
Python :: discord bot delete messages python 
Python :: online python 
Python :: python unresolved import vscode 
Python :: python package for confluence 
Python :: python convert int to hex string 
Python :: how to get number after decimal point 
Python :: max heap python 
Python :: drop portion of string in dataframe python 
Python :: media pipe install ERROR: Could not find a version that satisfies the requirement mediapipe (from versions: none) 
Python :: translate french to english 
Python :: django oauth toolkit permanent access token 
Python :: destroy label tkinter 
Python :: python file back to beginning 
Python :: how to use the super 
Python :: how to convert pandas series to 2d numpy array 
Python :: Tensor.expand_as 
Python :: install python 3.8 on wsl 
Python :: vscode in browser github 
Python :: df add value at first index 
Python :: django error handling < form 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =