Função para Abrir uma Interface do tkinter no Centro da Tela em Python
Publicado por Mauricio Ferrari em 07/10/2021
[ Hits: 10.861 ]
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()
Instalando o Nulloy no Deepin 20 ou Debian 9
Melhor Controle de Memória de Strings em C
Fazendo o .Xresources funcionar no Linux Mint 20
Deixando o Google Chrome em modo Dark no Linux - Experimental
Interface gráfica para o p7zip no Linux Mint e Ubuntu
TP-1 Engine - motor para criação de jogos
Instalando o pyenv no Linux Mint e Ubuntu
Hardware Project Simulator 0.23 - Mais fácil ainda!
Referenciando linhas anteriores em um arquivo csv usando Pandas
Reproduzindo vídeos em modo texto no Linux
Programa IRPF - Guia de Instalação e Resolução de alguns Problemas
Criando uma Infraestrutura para uma micro Empresa
Criar entrada (menuentry) ISO no Grub
Como gerar qualquer emoji ou símbolo unicode a partir do seu teclado
Instalando o Pi-Hole versão v5.18.4 depois do lançamento da versão v6.0
Instalar o VIM 9.1 no Debian 12
Como saber o range de um IP público?
Muitas dificuldades ao instalar distro Linux em Notebook Sony Vaio PCG-6131L (VPCEA24FM)
Problema no boot do Linux Mint Cinnamon 22 (4)
Atualização do Google Chrome do Ubuntu [RESOLVIDO] (2)
Instalei Windows 11 e não alterou o Grub do Debian (1)
Jogos baixados na Central de Aplicativos mas que não abrem (0)