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.131 ]
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()
Instalando o p7zip-desktop no Deepin 20
Transmageddon 1.5 no Slackware Current e no Python 3.9 - É sério!
Nulloy - Você conhecia esse reprodutor de áudio?
Kazam 1.4.5 no Slackware Current
Instalando o Aplicativo de Videoconferência Zoom no Deepin 20
Executando um Programa Externo sem Impedir o Funcionamento do Programa em Python
EarSketch - Aplicativo online que usa Python para criar e remixar músicas
Instalando o IPython com extensão notebook no Linux Mint e Ubuntu
Nomes de arquivos e codificação
A produção de áudio e vídeo no Linux e as distribuições dedicadas a esse fim
Criptografando sua Home com Gocryptfs para tristeza do meliante
A Involução do Linux e as Lambanças Desnecessárias desde o seu Lançamento
O Journal no Linux para a guarda e consulta de logs do sistema
A evolução do Linux e as mudanças que se fazem necessárias desde o seu lançamento
Instalar Ubuntu com Btrfs + LUKS de forma fácil
Habilitando "hotcorner" no Ubuntu
Zen Kernel no Arch Linux (instalar e remover)
Como instalar e remover o kernel Liquorix
Fazendo o controle de Xbox 360 USB funcionar no One Piece Pirate Warriors 4 (Arch Linux/Steam)
Continuando meus tópicos anteriores (9)
Executar um programa em Rust (2)
Não consigo publicar screenshots no Viva o Linux [RESOLVIDO] (5)









