Ttk: how to make a frame look like a labelframe?

Creating Python ttk gui is easy and has mostly appearance and appearance (win7). I have a little problem:

I would like to have a frame that looks like ttk.LabelFrame, but without a label. Just omitting the text option will leave an ugly gap.

Also I cannot get the ttk.Frame border to look like a LabelFrame. Is there an elegant way to do this? Bonus karma if it works on all / most versions of Windows above xp.

It may work with styles, but the LabelFrame style properties look mostly empty (style.element_options ("border.relief")). Maybe I'm looking in the wrong place.

edit:

try: # python 3 from tkinter import * # from ... import * is bad from tkinter.ttk import * except: from Tkinter import * from ttk import * t = Tcl().eval print("tcl version: " + str(t("info patchlevel"))) print("TkVersion: " + str(TkVersion)) root = Tk() lF = LabelFrame(root, text=None) lF.grid() b = Button(lF, text='gonzo') b.grid() f = Frame(root, relief="groove") #GROOVE) f.grid() b2 = Button(f, text='gonzo') b2.grid() f2 = Frame(root, relief=GROOVE, borderwidth=2) f2.grid() b3 = Button(f2, text='gonzo') b3.grid() mainloop() 

output on win7 with freshly loaded python 3.2.3:

tcl version: 8.5.9

TkVersion: 8.5

output

Python 2.6.6 is also installed on this computer (same problem). Each installation seems to use the correct tk / tcl.

+4
source share
1 answer

OK, it seems like one of the solutions to get a LabelFrame without a space is to use an empty widget instead of text. So, slightly changing the first part of your example:

 # don't do the 'from tkinter import *' thing to avoid namespace clashes import tkinter # assuming Python 3 for simplicity sake import tkinter.ttk as ttk root = tkinter.Tk() f = tkinter.Frame(relief='flat') lF = ttk.LabelFrame(root, labelwidget=f, borderwidth=4) lF.grid() b = ttk.Button(lF, text='gonzo') b.grid() root.mainloop() 

It seems to work with the usual Win7 theme for me.

+5
source

Source: https://habr.com/ru/post/1434215/


All Articles