Python Forum
[Tkinter] ttk Separator sizing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] ttk Separator sizing
#1
I have been asked about information on how to size a ttk Separator using the .pack or .place methods.
In the code below the separator is showing however it is not the length required. The separator is supposed to go from the current placement (the bottom of the brown header and run to the bottom of the space to the brown footer in the image. As seen when running the code it only runs from the brown header to a little more then half way down.
Is there a way to resize the length and place it in the correct position?
I have attached the image being used in the code.

Code:
from tkinter import *
from tkinter import ttk
import win32api
import win32con
import pywintypes
root = Tk()
root.title(Prehistoric Life)
devmode = pywintypes.DEVMODEType()
devmode.PelsWidth = 1280
devmode.PelsHeight = 720
devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
win32api.ChangeDisplaySettings(devmode, 0)
header=PhotoImage(file='header.gif')
w = 1280
h = 720
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root.state('zoomed')
panel1 = Label(root, image=header)
panel1.pack(side='top', fill='both', expand='yes')
#-------------------------------- LABELS ---------------------------------------
name = Label(root, text = 'Name :', font = ('arial',10,'bold'), bg = '#E2DED6')
name.place(x=90, y = 200)
meaning = Label(root, text = 'Meaning :', font = ('arial',10,'bold'), bg = '#E2DED6')
meaning.place(x=72, y = 230)
pronounce = Label(root, text = 'Pronounciation :', font = ('arial',10,'bold'), bg = '#E2DED6')
pronounce.place(x=30, y = 260)
period = Label(root, text = 'Period :', font = ('arial',10,'bold'), bg = '#E2DED6')
period.place(x=85, y = 290)
group = Label(root, text = 'Group :', font = ('arial',10,'bold'), bg = '#E2DED6')
group.place(x=89, y = 320)
size = Label(root, text = 'Size :', font = ('arial',10,'bold'), bg = '#E2DED6')
size.place(x=100, y = 350)
lived = Label(root, text = 'Lived :', font = ('arial',10,'bold'), bg = '#E2DED6')
lived.place(x=93, y = 380)
diet = Label(root, text = 'Diet :', font = ('arial',10,'bold'), bg = '#E2DED6')
diet.place(x=102, y = 410)
fossils = Label(root, text = 'Fossils :', font = ('arial',10,'bold'), bg = '#E2DED6')
fossils.place(x=85, y = 440)
#------------------------------ ENTRY BOX --------------------------------------
eName = Entry(root, width = 30, bg = '#d8d3cf')
eName.place(x=150, y = 203)
eMeaning = Entry(root, width = 30, bg = '#d8d3cf')
eMeaning.place(x= 150, y = 233)
ePronounce = Entry(root, width = 30, bg = '#d8d3cf')
ePronounce.place(x= 151, y = 263)
ePeriod = Entry(root, width = 30, bg = '#d8d3cf')
ePeriod.place(x= 151, y = 293)
eGroup = Entry(root, width = 30, bg = '#d8d3cf')
eGroup.place(x= 151, y = 323)
eSize = Entry(root, width = 30, bg = '#d8d3cf')
eSize.place(x= 151, y = 353)
eLived = Entry(root, width = 30, bg = '#d8d3cf')
eLived.place(x= 151, y = 383)
eDiet = Entry(root, width = 30, bg = '#d8d3cf')
eDiet.place(x= 151, y = 413)
eFossils = Entry(root, width = 30, bg = '#d8d3cf')
eFossils.place(x= 151, y = 443)
#-------------------------------- SEPARATOR ------------------------------------
s = ttk.Separator(panel1, orient=VERTICAL)
s.pack(side=LEFT, fill="y", padx=345, pady=177)
#------------------------------- TEXT WIDGET -----------------------------------
factFile = Text(root, x=360, y= 210, height=27, width=60, bg = '#d8d3cf', wrap=WORD)
factFile.place(x=360, y=200)
for line in range(1001):
  factFile.insert(END, "Row: " + str(line + 1))
root.mainloop()
win32api.ChangeDisplaySettings(None, 0)

Attached Files

Thumbnail(s)
   
"Often stumped... But never defeated."
Reply
#2
you can create your own, then set width background whatever yourself:
You can change the height and border as desires, or change to pass as arguments
This code untested, but should be close if not there.
Requires Pmw pip install pmw

import tkinter as tk
import Pmw


class Separator(Pmw.MegaWidget):
    def __init__(self, parent=None, **kw):
        # Define the options for the megawidget
        def __createSeparator(self):
            self.__separator = self.createcomponent('separator',(), None,
            Frame,(self._hull,),
            relief=SUNKEN, bd=2, height=2)
            self.__separator.pack(fill=X, expand=YES)

if __name__ == '__main__':
    Separator()
Reply
#3
Thank you... much appreciated.
"Often stumped... But never defeated."
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter frame sizing problems Lux 0 4,895 Aug-26-2017, 06:09 PM
Last Post: Lux
  [Tkinter] Thousand Separator Entry Widget Cursor Pos Trouble papatubies 4 5,173 Jul-24-2017, 02:51 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020