Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

375
Views
Mezcle PanedWindow() vertical y horizontal en tkinter y mueva las fajas juntas

Acabo de empezar a usar tkinter y me siento bien al respecto, pero ahora me enfrento a un problema y parece que no puedo encontrar nada al respecto. Actualmente estoy tratando de crear esta forma con PanedWindow():

 ########|####### # | # --------|------- # | # ########|#######

Actualmente tengo un código que crea esta forma y puedo cambiar el tamaño de las ventanas del panel (- & |) . El problema es que necesito que estos (|) se muevan juntos como estos (-) . Si eso no quedó claro, estoy tratando de juntar los divisores centrales. Actualmente, son así:

 ###|############ # | # ---------------- # | # ############|###

Si esto todavía no está claro, ¡pruébalo! Pongo el código a continuación. Como puede ver, puede juntar las líneas verticales, pero no las horizontales. Sé que la razón es que hay 2 ventanas de panel independientes dentro de una ventana de panel principal, por lo que actúan de forma independiente. ¡Todavía no sé cómo podría unirlos!

 from tkinter import * master = Tk() master.geometry("400x400") # Main Pane main_panel = PanedWindow(orient=VERTICAL, bd=2, relief="solid", bg="black") main_panel.pack(fill="both", expand=1) # Sub Panes ############################################################################## top_left = PanedWindow(main_panel, bd=1, relief="solid", bg="black") top_left.pack(fill="both", expand=1) left_label = Label(top_left, text= "Left-top") top_left.add(left_label) top_right = PanedWindow(top_left, orient=VERTICAL, bd=4) top_left.add(top_right) right_label = Label(top_left, text= "Right-top") top_right.add(right_label) ############################################################# bottom_left = PanedWindow(main_panel, bd=1, relief="solid", bg="black") bottom_left.pack(fill="both", expand=1) left_label = Label(bottom_left, text= "Left-bottom") bottom_left.add(left_label) bottom_right = PanedWindow(bottom_left, orient=VERTICAL, bd=4) bottom_left.add(bottom_right) right_label = Label(bottom_left, text= "Right-bottom") bottom_right.add(right_label) main_panel.add(top_left) main_panel.add(bottom_left) mainloop()
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Traté de encontrar una solución más general a este problema, ya que pensé que quizás desee agregar más ventanas con paneles a main_panel. De todos modos, esto se puede lograr con menos líneas de código, pero para la demostración lo hice con más pasos de los necesarios.

Referencias:

  • Nivel de enlaces
  • Métodos para PanedWindow
  • objetos de evento
  • métodos universales de widgets

 import tkinter as tk #dont use wildcard imports def onB1Motion(event):#bindings are executed with event objects widget = event.widget #get widget/paned window of event x,y = event.x,event.y #get x and y coord of event data = widget.identify(x,y) #paned window identify if data != '': #identify returns empty string if child window idx = data[0] #get sash index orient = event.widget['orient'] #check for orientation of paned window for child in widget.master.winfo_children(): #get all children of master if isinstance(child,tk.PanedWindow): #if children is paned window do.. if child['orient'] == orient: #if child paned window is same orient as event paned do.. child.sash_place(idx,x,y) #places the sash with same index on same position LABEL_WIDTH = 10 #simulate natural size by label width master = tk.Tk() master.geometry("400x400") # Main Pane main_panel = tk.PanedWindow(orient=tk.VERTICAL, bd=2, relief="solid", bg="black") main_panel.pack(fill="both", expand=1) # Sub Panes ############################################################################## top_left = tk.PanedWindow(main_panel, bd=1, relief="solid", bg="black") top_left.pack(fill="both", expand=1) left_label = tk.Label(top_left,width=LABEL_WIDTH, text= "Left-top") top_left.add(left_label) top_right = tk.PanedWindow(top_left, orient=tk.VERTICAL, bd=4) top_left.add(top_right) right_label = tk.Label(top_left,width=LABEL_WIDTH, text= "Right-top") top_right.add(right_label) ############################################################################## bottom_left = tk.PanedWindow(main_panel, bd=1, relief="solid", bg="black") bottom_left.pack(fill="both", expand=1) left_label = tk.Label(bottom_left,width=LABEL_WIDTH, text= "Left-bottom") bottom_left.add(left_label) bottom_right = tk.PanedWindow(bottom_left, orient=tk.VERTICAL, bd=4) bottom_left.add(bottom_right) right_label = tk.Label(bottom_left,width=LABEL_WIDTH, text= "Right-bottom") bottom_right.add(right_label) ############################################################################## main_panel.add(top_left) main_panel.add(bottom_left) ##binding class/all paned windows to execute command {onB1Motion} by {B1-Motion} ## USE ADD=+ TO DONT OVERWRITE THE STANDARD ONE master.bind_class(main_panel.winfo_class(),'<Button1-Motion>',onB1Motion,add='+') master.mainloop()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!