Função para Abrir uma Interface do tkinter no Centro da Tela em Python
Publicado por Mauricio Ferrari em 07/10/2021
[ Hits: 11.110 ]
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()
dvd::rip no Linux Mint 20 na gambiarra
Instalando o BootUp Manager (BUM) no Ubuntu 20.04 e Linux Mint 20
Instalando o Aplicativo de Videoconferência Zoom no Deepin 20
Liberando o ctrl+s e o ctrl+q para o VIM
Instalando o Spotify no Slackware de forma funcional
Hardware Project Simulator 0.23 - Mais fácil ainda!
"RPG Maker" escrito em Python e Pygame
Referenciando linhas anteriores em um arquivo csv usando Pandas
TradutorOOoNote - plugin para OpenOffice.org que traduz textos para qualquer língua
EarSketch - Aplicativo online que usa Python para criar e remixar músicas
Aprenda a Gerenciar Permissões de Arquivos no Linux
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Como instalar o Google Cloud CLI no Ubuntu/Debian
Mantenha seu Sistema Leve e Rápido com a Limpeza do APT!
Procurando vídeos de YouTube pelo terminal e assistindo via mpv (2025)
Alguém que utilize o Warsaw do BB no Ubuntu 24.04 (1)
Usar uma VM dentro do meu notebook como firewall para um dispositivo e... (1)