1

when i use tkinter button i get the results i want though i'm using tkinter button from tkmacosx library as it supports background color. The problem is when i replace normal button with tkmacosx button they appear like dots.

import tkinter as tk
import tkmacosx as tkm
from tkinter.font import Font

root = tk.Tk()
color_list = ('#462066', '#FFB85F', '#FF7A5A', 
              '#00AAA0', '#8ED2C9', '#FCF4D9')

button_font = Font(family="Comic Sans MS", size='30')

for row, bg in enumerate(color_list):
    b1 = tkm.Button(
        root, text='%s'%row, bg=bg, borderless=1,
        width=5, height=3, font=button_font)
    b1.grid(row=row%2, column=row%3)
root.mainloop()

images:

tkmacosx buttons appear like this this but i want the button to sizes like this.

Thanks

jorden435
  • 13
  • 2
  • 1
    My guess is that `tkmacosx.Button`'s width is in pixels not characters. Also if you just use `tk.Button` you aren't going to have that problem. Why are you using `tkmacosx`? I don't have a MacOS so I have no glue what that is – TheLizzard May 04 '21 at 16:04
  • Hi @TheLizzard, In macos we cannot change bg and fg of the button tkmacosx let u do that. you can see that here https://stackoverflow.com/questions/1529847/how-to-change-the-foreground-or-background-colour-of-a-tkinter-button-on-mac-os – jorden435 May 04 '21 at 16:21
  • You can also give width and height like `width='5c', height='3c'`. Where *"c" means centimetres*. There are also few other units as well like "I": inches, "m": millimetres and "p": points. – Saad May 04 '21 at 18:34

1 Answers1

2

you need to increase number of pixels width= 200, height = 100

import tkinter as tk
import tkmacosx as tkm
from tkinter.font import Font

root = tk.Tk()
color_list = ('#462066', '#FFB85F', '#FF7A5A',
              '#00AAA0', '#8ED2C9', '#FCF4D9')

button_font = Font(family="Comic Sans MS", size='30')

for row, bg in enumerate(color_list):
    b1 = tkm.Button(root, width=200,  height=100,  text='%s' % row, bg=bg, borderless=1,  font=button_font)
    b1.grid(row=row % 2, column=row % 3)
root.mainloop()

here is output output

TheLizzard
  • 7,248
  • 2
  • 11
  • 31
Ramesh
  • 504
  • 5
  • 9