Função para Abrir uma Interface do tkinter no Centro da Tela em Python
Publicado por Mauricio Ferrari em 07/10/2021
[ Hits: 11.557 ]
Blog: https://www.youtube.com/@LinuxDicasPro
def center(win):
# :param win: the main window or Toplevel window to center
# Apparently a common hack to get the window size. Temporarily hide the
# window to avoid update_idletasks() drawing the window in the wrong
# position.
win.update_idletasks() # Update "requested size" from geometry manager
# define window dimensions width and height
width = win.winfo_width()
frm_width = win.winfo_rootx() - win.winfo_x()
win_width = width + 2 * frm_width
height = win.winfo_height()
titlebar_height = win.winfo_rooty() - win.winfo_y()
win_height = height + titlebar_height + frm_width
# Get the window position from the top dynamically as well as position from left or right as follows
x = win.winfo_screenwidth() // 2 - win_width // 2
y = win.winfo_screenheight() // 2 - win_height // 2
# this is the line that will center your window
win.geometry('{}x{}+{}+{}'.format(width, height, x, y))
# This seems to draw the window frame immediately, so only call deiconify()
# after setting correct window position
win.deiconify()
import tkinter as tk
main_app = tk.Tk()
main_app.attributes('-alpha', 0.0) # Opcional, para deixar a janela totalmente transparente até os ajustes serem feitos.
main_app.minsize(500, 300)
center(main_app) # A função
main_app.attributes('-alpha', 1.0) # A interface fica visível novamente.
main_app.mainloop()
Corrigindo a Falha de Segmentação do VirtualBox 6.1.18 no Slackware Current [RESOLVIDO]
Diminuindo o Tempo de Inicialização do Linux Mint
Erro ao Instalar o "ttf-mscorefonts-installer" no Ubuntu [Resolvido]
Última atualização do Bleachbit para Diversas Distribuições
Instalando corretamente o Wine atualizado no Debian, Ubuntu, Linux Mint e derivados
TradutorOOoNote - plugin para OpenOffice.org que traduz textos para qualquer língua
Spyder - Excelente IDE para desenvolver em Python
Obtendo mirrors mais velozes no Arch Linux
Como alterar a versão default (padrão) do Python no Linux
Hardware Project Simulator 0.1 - Simulador de montagem de computadores
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
IA Turbina o Desktop Linux enquanto distros renovam forças
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Como realizar um ataque de força bruta para desobrir senhas?
Como usar Gpaste no ambiente Cinnamon
Atualizando o Fedora 42 para 43
Scripts ou binários [RESOLVIDO] (3)
VOL já não é mais como antes? (10)
Pergunta: Meu teclado não está respondendo direito como e consertar? ... (4)









