Tkinter button height changes when compound option reconfigured from none to any other value

I’m trying to add to my application a couple of buttons with an image and text. By default all buttons have hidden text by setting:

compound=tk.NONE

When one specific button is pushed – compound is switched to any other value, for example

compound=tk.LEFT

Then button height change can be observed. I can’t understand why. Maybe it is normal behavior or what is more probable – maybe it’s my fault and some additional/different setups are needed.
I read that when a button has specified image and text then its size input values are processed as pixels not as a font character size. In my case its true, checked that a font size doesn’t impact button height.

I have prepared simple application that present this problem:

import tkinter as tk

class psWindow():
    def __init__(self, parent) -> None:
        self.parent = parent
       
        #Main window geometry
        self.setParentGeometry()

        #Parent grid weight
        self.parent.grid_columnconfigure(0,weight=1)
        self.parent.grid_rowconfigure(0,weight=1)

        #Frame 1, spread to parent size
        self.frame1 = tk.Frame(parent,height=50,
                               width=50,background='black',borderwidth=0, highlightthickness=0)
        self.frame1.grid(column=0,row=0,sticky=tk.NSEW)

        #Frame 1 grid weight
        self.frame1.grid_columnconfigure(0,weight=1)
        self.frame1.grid_rowconfigure(0,weight=1)
        self.frame1.grid_rowconfigure(1,weight=1)

        #Some button global properties
        self.buttonWidth = 50
        self.fontList1 = ['Calibri', '12']

        #Dummy image, 1x1 pixel
        self.dummyImgB1 = tk.PhotoImage(width=1,height=1)

        #Button 1
        self.b1 = tk.Button(self.frame1, borderwidth=0, highlightthickness=0,
                            text='Button height changes', font=self.fontList1, 
                            background='orange', width=self.buttonWidth,
                            height=40, image=self.dummyImgB1, compound=tk.NONE,
                            command=self.unwrapMenu)
        self.b1.grid(column=0,row=0,sticky=tk.NSEW)

        #Button 2
        self.b2 = tk.Button(self.frame1, borderwidth=0, highlightthickness=0,
                        text='No text', font=self.fontList1, 
                        background='lime', width=self.buttonWidth,
                        height=60, image=self.dummyImgB1, compound=tk.NONE)
        self.b2.grid(column=0,row=1,sticky=tk.NSEW)      
 
    def setParentGeometry(self) -> None:
        self.parent.geometry('200x100+200+200')
        self.parent.maxsize(200,100)
        self.parent.minsize(200,100)
        self.parent.update()

    def unwrapMenu(self) -> None:

        #Switch command, set nonzero compound value to show text
        self.b1.configure(command=self.wrapMenu,
                          compound=tk.LEFT)

        #Get size of button 1 and print it 
        x = self.b1.winfo_width()
        y = self.b1.winfo_height()
        s = 'Button 1 (wrapped) size: x=' + repr(x) + ', y=' + repr(y)
        print(s)

        #Get size of button 2 and print it 
        x = self.b2.winfo_width()
        y = self.b2.winfo_height()
        s = 'Button 2 (wrapped) size: x=' + repr(x) + ', y=' + repr(y)
        print(s)
    
    def wrapMenu(self) -> None:

        #Switch command, set compound value to none to hide text
        self.b1.configure(command=self.unwrapMenu,
                          compound=tk.NONE)

        #Get size of button 1 and print it 
        x = self.b1.winfo_width()
        y = self.b1.winfo_height()
        s = 'Button 1 (unwrapped) size: x=' + repr(x) + ', y=' + repr(y)
        print(s)

        #Get size of button 2 and print it 
        x = self.b2.winfo_width()
        y = self.b2.winfo_height()
        s = 'Button 2 (unwrapped) size: x=' + repr(x) + ', y=' + repr(y)
        print(s)       

# create main window
window = tk.Tk()
app = psWindow(window)
window.mainloop()

200×100 app window with two buttons, first with 40 pix height, second with 60 pix height. Both have an image (1×1 pixel size) and text (by default hidden). When orange button is clicked then its text is showed and its height changes.

Button text hidden
Button text showed

Printed output:

Button 1 (wrapped) size: x=200, y=40
Button 2 (wrapped) size: x=200, y=60
Button 1 (unwrapped) size: x=200, y=44
Button 2 (unwrapped) size: x=200, y=56

So after text is enabled by setting compound option to tk.LEFT, button height gains additional 4 pixels in aid of second one.

What I am doing wrong? Thank you for your valuable input!

New contributor

MacSell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật