Ich erkunde Tkinter in Python3 und habe gerade mein erstes GUI-Projekt gestartet. Ich versuche, das Gitterpositionierungssystem und 3 Frames zu verwenden, um ein einfaches Layout wie folgt zu erstellen:Wie erstellt man ein einfaches Fenster mit 3 Frames und dynamischem Layout in Python3/tkinter mit Grid?
- Top Rahmen: Werkzeugleiste, einige Tasten, vielleicht ein Suchfeld (sollte immer sichtbar sein und halten Sie sich an die Anfang des Fensters und erstreckt sich ganz von links nach rechts).
- Hauptrahmen: Treeview, zum Abrufen von Werten aus einer Datenbank (sollte oben bleiben, direkt unter dem oberen Rahmen, erweitert von links nach rechts, und sollte auch erweitert werden, um den ganzen von oben und unten verbleibenden Platz zu nehmen) Rahmen).
- Bodenrahmen: Dateneingabeformular, Statusleiste ... (soll den unteren Rand des Fensters bleiben, von links nach rechts erweitert und Raum mit dem Hauptrahmen verlassen
ich gewesen. herumalbern mit Rahmen und Gewichten und es scheint immer etwas falsch zu sein.Wenn ich das Fenster klein genug verkleinere, verbirgt der Hauptrahmen teilweise den oberen Rahmen.Wenn ich das Fenster vergrößere, dehnen sich der Hauptrahmen und die Baumansicht nichtvollständig aus Wie gewünscht, kann jemand helfen?
Hier ist mein Code, wie ich es gerade habe:
#!/usr/local/bin/python3
# encoding: utf-8
"""
docstring
"""
import sys
import os
import os.path
import csv
import re
from platform import node
from tkinter import *
from tkinter import ttk
__app_name__ = "APP NAME"
__version__ = "0.0.1"
def add_remessa():
pprint("REMESSA")
def click_btn_hoje():
print("HOJE")
root = Tk()
root.title(__app_name__+" "+__version__)
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
topframe = ttk.Frame(root, padding="3 3 12 12")
topframe.grid(column=0, row=0, sticky=(N, E, W))
topframe.columnconfigure(0, weight=1)
topframe.columnconfigure(1, weight=1)
topframe.rowconfigure(0, weight=1)
topframe.rowconfigure(0, weight=1)
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=1, sticky=(N, W, E))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
bottomframe = ttk.Frame(root, padding="3 3 12 12")
bottomframe.grid(column=0, row=2, sticky=(W, E, S))
bottomframe.columnconfigure(0, weight=1)
bottomframe.columnconfigure(1, weight=1)
bottomframe.rowconfigure(0, weight=1)
bottomframe.rowconfigure(0, weight=1)
def NovaRemessa():
print("Nova remessa!")
def EditarRemessa():
print("Editar")
def About():
print("This is a simple example of a menu")
def painelAddRemessa():
print("Mostrar painel de introdução de nova remessa")
btn_quit = ttk.Button(topframe, text="+", command=painelAddRemessa)
btn_quit.grid(row=0, column=6, sticky=E+N)
btn_quit = ttk.Button(topframe, text=" Sair ", command=exit)
btn_quit.grid(row=0, column=1, sticky=E+N)
# Data entry form
obj_num = StringVar()
destin = StringVar()
cobr = StringVar()
dias = StringVar()
vols = StringVar()
ttk.Label(bottomframe, text="Nº Objeto").grid(row=5, column=0, sticky=W+S)
text_input_obj = ttk.Entry(bottomframe,textvariable=obj_num, width=13)
text_input_obj.grid(row=6, column=0, sticky=W+S)
text_input_obj.focus_set()
ttk.Label(bottomframe, text="Destinatário").grid(row=5, column=1, columnspan=1, sticky=W+S)
text_input_dest = ttk.Entry(bottomframe, textvariable=destin, width=25)
text_input_dest.grid(row=6, column=1, sticky=W+S)
ttk.Label(bottomframe, text="Cobrança").grid(row=5, column=2, sticky=W+E+S)
text_input_cobr = ttk.Entry(bottomframe, textvariable=cobr, width=7)
text_input_cobr.grid(row=6, column=2, sticky=W+E+S)
ttk.Label(bottomframe, text="Dias").grid(row=5, column=3, sticky=W+E+S)
text_input_dias = ttk.Entry(bottomframe, textvariable=dias, width=4)
text_input_dias.grid(row=6, column=3, sticky=W+E+S)
ttk.Label(bottomframe, text="Volumes").grid(row=5, column=4, sticky=W+E+S)
text_input_vols = ttk.Entry(bottomframe, textvariable=vols, width=5)
text_input_vols.grid(row=6, column=4, sticky=W+E+S)
# Botões
btn_add = ttk.Button(bottomframe, text=" Adicionar ", command=add_remessa).grid(row=6, column=6,sticky=W+E+S)
ttk.Label(mainframe, text="Nº de remessas: XXXX").grid(row=2, column=0, columnspan=2, sticky=W)
ttk.Label(mainframe, text="Valor a cobrar: XXXXXX").grid(row=2, columnspan=2, column=2)
ttk.Label(mainframe, text="Recebido: XXXXX").grid(row=2, column=4)
ttk.Label(mainframe, text="Depositar: XXXXXXX").grid(row=2, column=6, sticky=E)
tree = ttk.Treeview(mainframe, selectmode='extended')
tree['columns'] = ('ID', 'Dias', 'Destinatário', 'Estado', 'Objeto nº', 'Cobr.', 'Chq.rec.', 'Depositar')
tree.grid(row=0, column=0, columnspan=7, sticky=N+W+E+S)
tree.column('#0', anchor=W, minwidth=0, stretch=0, width=0)
tree.column('ID', anchor=W, minwidth=30, stretch=1, width=30)
tree.column('Dias', minwidth=30, stretch=1, width=30)
tree.column('Destinatário', minwidth=100, stretch=1, width=200)
tree.column('Estado', minwidth=100, stretch=1, width=180)
tree.column('Objeto nº', minwidth=50, stretch=1, width=80)
tree.column('Cobr.', minwidth=60, stretch=1, width=60)
tree.column('Chq.rec.', minwidth=80, stretch=1, width=80)
tree.column('Depositar', anchor=E, minwidth=80, stretch=1, width=80)
tree.heading('ID', text="ID")
tree.heading('Dias', text="Dias")
tree.heading('Destinatário', text="Destinatário")
tree.heading('Estado', text="Estado")
tree.heading('Objeto nº', text="Objeto nº")
tree.heading('Cobr.', text="Cobr.")
tree.heading('Chq.rec.', text="Chq.rec.")
tree.heading('Depositar', text="Depositar")
for child in mainframe.winfo_children(): child.grid_configure(padx=1, pady=1)
mainloop()
Sie benötigen nicht den gesamten Code, um das Problem zu veranschaulichen. Bitte lesen Sie http://www.stackoverflow.com/help/mcve –
Entschuldigung! Ich habe gerade einige Teile des Codes entfernt, von denen ich glaube, dass sie nicht mit dem Problem zusammenhingen, das ich jetzt zu lösen versuche. –