Função para Abrir uma Interface do tkinter no Centro da Tela em Python
Publicado por Mauricio Ferrari (LinuxProativo) em 07/10/2021
[ Hits: 12.005 ]
Blog: https://www.youtube.com/@LinuxProativo
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()
Evitando Propagandas e Sites Golpistas no Google Chrome
Definindo um Título para o Terminal do Linux
Ícone do atunes não aparece no Menu Inicial no Slackware
Fazendo o .Xresources funcionar no Linux Mint 20
Copiar apenas os arquivos e não os diretórios
Nomes de arquivos e codificação
Como descobrir seu chat_id no Telegram
Instalando o pyenv no Linux Mint e Ubuntu
Criando aplicativos multiplataforma (Android, iOS, Windows) com Python + Kivy
Python - Diferença entre == e is
Instalação e Configuração do Void com Cinnamon
Porque Gentoo semi-binário atualmente (desabafo)
A combinação de WMs com compositores feitos por fora
Audacious, VLC e QMMP - que saudades do XMMS
SUNO OpenSource: Crie um servidor de gerador de música com IA
Guia de instalação do Gentoo Linux com Cinnamon (UEFI, LUKS2, Btrfs)
Aparecer o Chuck Norris no seu terminal
Da pra formatar um netbook MGB e usar algum linux nele? É possível usa... (2)
Alguns aplificativos em Flatpak não rodam no Debian (4)
CachyOS vs Arch [RESOLVIDO] (11)
Um filme, uma banda, um jogo, um livro, um anime (ou mangá) (13)









