Função para Abrir uma Interface do tkinter no Centro da Tela em Python
Publicado por Mauricio Ferrari em 07/10/2021
[ Hits: 10.619 ]
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()
Resolvendo o "Could not open /dev/vmmon" do VMWare no Linux
Formas de Obter as Dimensões do Emulador Terminal
brModelo 3.3 empacotado para o Linux Mint 20
Métodos para a Limpeza do Terminal do Linux em C
Player Nulloy no Ubuntu 20.04, Linux Mint 20 e derivações mais atuais - atualização
Crie o seu jogo roguelike em Python
Instalando o pyenv no Linux Mint e Ubuntu
Spyder - Excelente IDE para desenvolver em Python
TP-1 Engine - motor para criação de jogos
Como descobrir seu chat_id no Telegram
Passkeys: A Evolução da Autenticação Digital
Instalação de distro Linux em computadores, netbooks, etc, em rede com o Clonezilla
Título: Descobrindo o IP externo da VPN no Linux
Armazenando a senha de sua carteira Bitcoin de forma segura no Linux
Enviar mensagem ao usuário trabalhando com as opções do php.ini
Instalação Microsoft Edge no Linux Mint 22
Como configurar posicionamento e movimento de janelas no Lubuntu (Openbox) com atalhos de teclado
Máquinas Virtuais com IP estático acessando Internet no Virtualbox
Por que o wine trava tanto? (3)
Problemas na Atualização do Ubuntu 20.04 para 22.04 (8)