English 中文(简体)
窗户内存在的问题或分割框架(Python with Tkinter/TTKcks)
原标题:Problem placing or dividing frames in the window (Python with Tkinter/TTKbootstrap)

我试图将两只拉比塞放在彼此旁边,但我想一把窗子和另一半遮盖,但我却尝试了一切,但是他们只是在这个角落里停留了。

https://i.stack.imgur.com/GwUiI.png”rel=“nofollow noreferer” ,我想改为

我希望他们看一看我如何把他们描绘成形象,但他们只是留在角落。

from textwrap import fill
import tkinter as tk
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from PIL import Image, ImageTk


class APP:

    def __init__(self):
        # Criando a janela principal
        self.root = tk.Tk()
        self.root.title("FMD")
        self.root.geometry("1080x600")  # Define o tamanho da janela
        # Impede o redimensionamento da janela
        self.root.resizable(False, False)

        # Carregando a imagem existente
        background_image = Image.open("background.png")

        # Convertendo a imagem para o formato Tkinter PhotoImage
        self.background_photo = ImageTk.PhotoImage(background_image)

        # Criando um rótulo com a imagem como plano de fundo
        self.background_label = tk.Label(
            self.root, image=self.background_photo)
        self.background_label.place(x=0, y=0, relwidth=1, relheight=1)

        # Criando o frame do Dataset
        self.dataset_frame = ttk.Frame(self.root, bootstyle="dark")
        self.dataset_frame.grid(row=0, column=0)

        self.dataset_label = ttk.Label(
            self.dataset_frame, text="Dataset:", bootstyle="inverse-dark")
        self.dataset_label.configure(font=("Arial", 16, "bold"))
        self.dataset_label.pack(side=LEFT)

        # Criando o frame do preview
        self.preview_frame = ttk.Frame(self.root, bootstyle="dark")
        self.preview_frame.grid(row=0, column=1)

        self.preview_label = ttk.Label(
            self.preview_frame, text="Preview:", bootstyle="sucess")
        self.preview_label.configure(font=("Arial", 16, "bold"))
        self.preview_label.pack(side=LEFT)

        # Inicia o loop principal da aplicação
        self.root.mainloop()


# Inicializa a aplicação
app = APP()
问题回答

I switched Grid to pack ( please anyone correct me if I am wrong but I could not find a way to easily configure the grid column ). By using winfo_width() you can get the width of the window/object.

from tkinter import *

#Tendrás que volver a agregar todas las imágenes e 
# importaciones, las eliminé para poder probarlas.

class APP:

    def __init__(self):
        # Criando a janela principal
        self.root = Tk()
        self.root.title("FMD")
        self.root.geometry("1080x600")  # Define o tamanho da janela
        # Impede o redimensionamento da janela
        self.root.resizable(False, False)

        # Criando o frame do Dataset
        
        # Esto actualiza los datos  raíz  utilizados para obtener el ancho.
        self.root.update()
        
        # A continuación, obtenga el ancho de la aplicación y divídalo por dos.
        self.dataset_frame = Frame(self.root, width=round(self.root.winfo_width()/2), height=30)
        self.dataset_frame.pack(side=LEFT, anchor=NW)
        
        # Esto está aquí para que el marco no colapse (sin esta línea el marco tendrá un tamaño: 0x0)
        self.dataset_frame.pack_propagate(False)

        self.dataset_label = Label(self.dataset_frame, text="Dataset:", font=("Arial", 16, "bold"))
        self.dataset_label.pack()

        # Criando o frame do preview
        self.preview_frame = Frame(self.root, width=round(self.root.winfo_width()/2), height=30)
        self.preview_frame.pack(side=LEFT, anchor=NW)
        self.preview_frame.pack_propagate(False)

        self.preview_label = Label(self.preview_frame, text="Preview:", font=("Arial", 16, "bold"))
        self.preview_label.pack()

        # Inicia o loop principal da aplicação
        self.root.mainloop()


# Inicializa a aplicação
app = APP()

I want one to cover half the window and the other the other half but I ve tried everything but nothing happens they just stay in that corner

这个问题是可以确定的。

  • Add width and anchor in Label widgets.

Snippet:

self.dataset_label = ttk.Label(self.dataset_frame,
                                       width=50, anchor="n", text="Dataset:",
                                       bootstyle="inverse-dark")

并且

self.preview_label = ttk.Label(self.preview_frame,
                               width=50, anchor="n",
                               text="Preview:",
                               bootstyle="sucess")

检查:

“entergraph





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签