Home > Mobile >  Tkinter LabelFrame - How to change width?
Tkinter LabelFrame - How to change width?

Time:11-06

I'm new to python, and I am trying to implement an application using tkinter.

I am trying to build a LabelFrame, but I struggle to change the width of the frame.

I want to make all three LabelFrames the same width.

How can I do this? This is how the application looks right now: enter image description here

This is my code:

import tkinter as tk 
from tkinter import *
from tkinter import ttk

import pip
from tkcalendar import Calendar, DateEntry
from tkcalendar import *

# needs to inherit imports from ui_imports

#Screen erstellen
lastenheft_screen2 = tk.Tk()

#Größe des Screens
lastenheft_screen2.geometry("1400x1000")
lastenheft_screen2.resizable(False, False)

#Titel
lastenheft_screen2.title("Lastenheft")

#Titel 'Ziele der Software-Einfuehrung'
zieledersoftwareeinfuehrung_label = Label(lastenheft_screen2, text = 'Ziele der Softwareeinführung: ', font = ('bold', 20), pady = 10)
zieledersoftwareeinfuehrung_label.grid (row = 0, column = 0, columnspan=1, rowspan =1, pady = 10, padx = 10)
    
#Titel 'Allgemeines'
allgemeinedaten_frame = LabelFrame(lastenheft_screen2, text = "Allgemeines: ", font = ('bold', 12), pady = 10, padx = 10)
allgemeinedaten_frame.grid(row = 1, column = 0,sticky = W, padx = 10, pady = 10)
    
#Objekt 'Anlass der Software-Einfuehrung'
anlass_text = StringVar()
anlass_label = Label(allgemeinedaten_frame, text = 'Anlass der Softwareeinführung: ', font = ('normal', 10), pady = 10)
anlass_label.grid (row = 2, column = 0, sticky = W, pady = 10, padx = 10)
anlass_box = Text(allgemeinedaten_frame, height= 3, width= 80)
anlass_box.grid(row = 2, column = 1)

#Objekt 'Kurzbeschreibung der zu erbringenden Leistung'
erbringeneleistung_text = StringVar()
erbringeneleistung_label = Label(allgemeinedaten_frame, text = 'Kurbeschreibung der zu erbringenden Leistung: ', font = ('normal', 10), pady = 10)
erbringeneleistung_label.grid (row = 5, column = 0, sticky = W, pady = 10, padx = 10)
erbringeneleistung_box = Text(allgemeinedaten_frame, height= 3, width= 80)
erbringeneleistung_box.grid(row = 5, column = 1)

#Objekt 'Ziele der Einfuehrung'
zieleinfuehrung_text = StringVar()
zieleinfuehrung_label = Label(allgemeinedaten_frame, text = 'Ziele der Einführung: ', font = ('normal', 10), pady = 10)
zieleinfuehrung_label.grid (row = 8, column = 0, sticky = W, pady = 10, padx = 10)
zieleinfuehrung_box = Text(allgemeinedaten_frame, height= 3, width= 80)
zieleinfuehrung_box.grid(row = 8, column = 1)

#Titel 'Zeitliche Grobplanung'
zeitlicheplanung_frame = LabelFrame(lastenheft_screen2, text = "Zeitliche Grobplanung: ", font = ('bold', 12), width = 250, pady = 10, padx = 10)
zeitlicheplanung_frame.grid(row = 2, column = 0,sticky = NW, padx = 10, pady = 10)
 
#Objekt 'Geplanter Beginn'
geplanterbeginn_text = StringVar()
geplanterbeginn_label = Label(zeitlicheplanung_frame, text = 'Geplanter Beginn: ', font = ('normal', 10), pady = 10)
geplanterbeginn_label.grid (row = 12, column = 0, sticky = W, pady = 10, padx = 10)
geplanterbeginn_box = Text(zeitlicheplanung_frame, height= 3, width= 80)
geplanterbeginn_box.grid(row = 12, column = 1)

#Objekt 'Voraussichtliches Ende'
voraussichtlichesende_text = StringVar()
voraussichtlichesende_label = Label(zeitlicheplanung_frame, text = 'Voraussichtliches Ende: ', font = ('normal', 10), pady = 10)
voraussichtlichesende_label.grid (row = 15, column = 0, sticky = W, pady = 10, padx = 10)
voraussichtlichesende_box = Text(zeitlicheplanung_frame, height= 3, width= 80)
voraussichtlichesende_box.grid(row = 15, column = 1)

#Titel 'Sonstiges'
sonstiges_frame = LabelFrame(lastenheft_screen2, text = "Sonstiges: ", font = ('bold', 12), width = 4550, pady = 10, padx = 10)
sonstiges_frame.grid(row = 3, column = 0,sticky = NW, padx = 10, pady = 10)

#Objekt 'Sonstiges'
sonstiges_text = StringVar()
sonstiges_label = Label(sonstiges_frame, text = '  ', font = ('normal', 10), pady = 10)
sonstiges_label.grid (row = 19, column = 0, sticky = W, pady = 10, padx = 10)
sonstiges_box = Text(sonstiges_frame, height= 3, width= 80)
sonstiges_box.grid(row = 19, column = 1)

def save_data():
    #this function intends do be a connection to the database
    pass

def discard_data():
    #this function intends do be a connection to the database
    pass

def clear_data():
    pass

#Buttons
buttons_frame = LabelFrame(lastenheft_screen2, text = "Options: ", font = ('bold', 12), pady = 10, padx = 10)
buttons_frame.grid(row = 5, column = 3,sticky=NE,  padx = 30, pady = 30)

save_button = Button(buttons_frame, text = 'Save changes', width = 12, command=save_data)
save_button.grid(row = 9, column = 0, padx = 10, pady = 10)

discard_button = Button(buttons_frame, text = 'Discard changes', width = 12, command=discard_data)
discard_button.grid(row = 9, column = 1, padx = 10, pady = 10)

clear_button = Button(buttons_frame, text = 'Clear all fields', width = 12, command=clear_data)
clear_button.grid(row = 9, column = 2, padx = 10, pady = 10)

#Start programm
lastenheft_screen2.mainloop()

CodePudding user response:

I think I've got the answer for you, just change your title sticky, on lines 52

zeitlicheplanung_frame.grid(row = 2, column = 0,sticky = "ew", padx = 10, pady = 10)

And 70

sonstiges_frame.grid(row = 3, column = 0,sticky = "ew", padx = 10, pady = 10)

That seems to do the trick on my end, but that might not be exactly what you're looking for

  • Related