“cara menambahkan tombol di tkinter” Kode Jawaban

cara menambahkan tombol di 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()
Tejas Naik

Tombol 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()
Zealous Zebra

Tambahkan tombol di Tkinter

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

cara membuat tombol menggunakan 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()
skiibloc

Tambahkan tombol di 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()

Poised Puma

Jawaban yang mirip dengan “cara menambahkan tombol di tkinter”

Pertanyaan yang mirip dengan “cara menambahkan tombol di tkinter”

Lebih banyak jawaban terkait untuk “cara menambahkan tombol di tkinter” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya