Função para Abrir uma Interface do tkinter no Centro da Tela em Python
Publicado por Mauricio Ferrari em 07/10/2021
[ Hits: 8.835 ]
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()
Compilando o Vim 8.2 com suporte a clipboard
Kazam 1.4.5 no Slackware Current
Usando o VirtualBox para Otimizar as VMs Instaladas no Genymotion
Executando um Programa Externo sem Impedir o Funcionamento do Programa em Python
Python: Somando valores em um dicionário de strings
Executando comandos do Shell Bash pelo Python
Vídeo sobre como participar do Google Summer of Code
Nenhum comentário foi encontrado.
Atenção a quem posta conteúdo de dicas, scripts e tal (2)
Manutenção de sistemas Linux Debian e derivados com apt-get, apt, aptitude e dpkg
Melhorando o tempo de boot do Fedora e outras distribuições
Como instalar as extensões Dash To Dock e Hide Top Bar no Gnome 45/46
Como Atualizar Fedora 39 para 40
Instalar Google Chrome no Debian e derivados
Consertando o erro do Sushi e Wayland no Opensuse Leap 15
Instalar a última versão do PostgreSQL no Lunix mantendo atualizado
Flathub na sua distribuição Linux e comandos básicos de gerenciamento
ASRock H310CM-HG4 vs Linux [RESOLVIDO] (19)
redirecionando saida de comando touch para o AWK[AJUDA] (8)
Manipulação de dados binários, aplicações (0)
Fedora 40 Melhor que Ubuntu 24.04 (7)
Microfone do meu headset não é recinhecido. Meu notebook é um Acer Asp... (13)