0

I have been doing a python app for a calculator with Tkinter. I want to know how access the buttons properties such as their size, height, width and color by the use of strings. So far I have been able to change the background of the lines behind the buttons to red by using style.configure("TButton", background='red', font="Serif 15", padding=10 ).

How do I change the buttons themselves? If anyone could help me I would greatly appreciate it.

from tkinter import *
from tkinter.ttk import *
from tkinter import ttk

class Calculator:

    calc_value = 0.0

    div_trigger = False
    mult_trigger = False
    add_trigger = False
    sub_trigger = False

    def __init__(self,root):

        self.entry_value = StringVar(root,value="")

        root.title("Calculator")


        root.geometry("600x500")

        root.resizable(width=True, height=True)

        style = ttk.Style()

        style.configure(self, background='red')
        style.configure("TButton", #background='red',
                        font="Serif 15",
                        padding=10 )
        style.configure("TEntry",
                        font="Serif 15",
                        padding=10 )
        self.number_entry = ttk.Entry(root, 
                        textvariable=self.entry_value,width=50)
        self.number_entry.grid(row=0, columnspan=4)

        #-------1st row---------

        self.button7 = ttk.Button(root, text="7",
             command=lambda: self.button_press('7')).grid(row=1, column=0)


        self.button8 = ttk.Button(root, text="8",
             command=lambda: self.button_press('8')).grid(row=1, column=1)

        self.button9 = ttk.Button(root, text="9",
             command=lambda: self.button_press('9')).grid(row=1, column=2)

        self.button_div = ttk.Button(root, text="/",
        command=lambda: self.button_press('/')).grid(row=1, column=3)

        #-------2nd row---------

        self.button4 = ttk.Button(root, text="4",
             command=lambda: self.button_press('4')).grid(row=2, column=0)

        self.button5 = ttk.Button(root, text="5",
             command=lambda: self.button_press('5')).grid(row=2, column=1)

        self.button6 = ttk.Button(root, text="6",
             command=lambda: self.button_press('6')).grid(row=2, column=2)

        self.button_mult = ttk.Button(root, text="*",
        command=lambda: self.button_press('*')).grid(row=2, column=3)

        #-------3rd row---------

        self.button1 = ttk.Button(root, text="1",
             command=lambda: self.button_press('1')).grid(row=4, column=0)

        self.button2 = ttk.Button(root, text="2",
             command=lambda: self.button_press('2')).grid(row=4, column=1)

        self.button3 = ttk.Button(root, text="3",
             command=lambda: self.button_press('3')).grid(row=4, column=2)

        self.button_add = ttk.Button(root, text="+",
        command=lambda: self.button_press('+')).grid(row=4, column=3)

        #-------4th row---------
        self.button_clear = ttk.Button(root, text="AC",
             command=lambda: self.button_press('AC')).grid(row=5, column=0)

        self.button0 = ttk.Button(root, text="0",
             command=lambda: self.button_press('0')).grid(row=5, column=1)

        self.button_equal = ttk.Button(root, text="=",
             command=lambda: self.button_press('=')).grid(row=5, column=2)

        self.button_sub = ttk.Button(root, text="-",
        command=lambda: self.button_press('-')).grid(row=5, column=3)


root = Tk()
calc = Calculator(root)
root.mainloop()

#button1 = Button(topframe,padx=16, pady=16, bd=8, text="1", fg="black", bg = random.choice(colors))
Keith Lashley
  • 27
  • 1
  • 6
  • 1
    Possible duplicate of [Changing ttk Button Height in Python](http://stackoverflow.com/questions/9927386/changing-ttk-button-height-in-python) – Lafexlos Mar 23 '17 at 06:23

1 Answers1

0

Here are documentatiopn about that.

http://effbot.org/tkinterbook/button.htm

If you want to change a botton size you can use.

button1.config(height = 100, width = 100)
SergioSalinas
  • 115
  • 1
  • 2
  • 11