Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to build Button controls with Tkinter

Shulou Source: shulou.com Published: 2022-06-01 03:35:47 10月01日 Update

This article introduces the knowledge of "how to build button controls in Tkinter". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The most common controls in GUI programs are buttons, so the next control description starts with buttons.

The code is as follows, and the reader can copy this code directly and execute the interface.

From tkinter import * from tkinter.font import *

Root = Tk ()

# create fontftTimes = Font (family='Times', size=24, weight=BOLD, slant=ITALIC)

# create a button to change state.state_button = Button (root,text= "ColorButton", background= "# ffffa0", foreground= "# ff0000", activebackground= "# a0ffa0", activeforeground= "# 0000ff", font=ftTimes, height=2) state_button.grid (row=0, column=0)

# change state function.def change_state (): state= state_button.cget ('state') if state==DISABLED: state_button.config (state=NORMAL) elif state==NORMAL: state_button.config (state=ACTIVE) else: state_button.config (state=DISABLED)

# change state button.Button (root,text= "

Tags: Buttons controls next objects states code functions content fonts properties scenery more knowledge background utility learning two functions actions just Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info MySQL Shulou Technology macOS