Função para Abrir uma Interface do tkinter no Centro da Tela em Python
Publicado por Mauricio Ferrari em 07/10/2021
[ Hits: 11.024 ]
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()
Expandindo o Til pelo Diretório Inicial do Usuário em Python
Cursores do Mandriva no Slackware
Instalando o Java 14 no Ubuntu, Linux Mint e Debian
Como empacotar programas compilados em DEB
Três Formas Fáceis de usar Super Usuário pelo Terminal no Linux
Instalando o pyenv no Linux Mint e Ubuntu
Reproduzindo vídeos em modo texto no Linux
Novo TradutorOOoNote substitui texto e envia o antigo para anotação
Spyder - Excelente IDE para desenvolver em Python
EarSketch - Aplicativo online que usa Python para criar e remixar músicas
Automatizando digitação de códigos 2FA no browser
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Como converter imagens PNG/JPEG para SVG em linha de comando
Fez porcaria no teu repositório Git? Aprenda a restaurar uma versão anterior do seu código!
Restaurando Fontes de Download do Hydra no Linux
Atualizando "na marra" o YT-DLP quando começa a dar erro de downloads
Como instalar o WPS com interface e corretor ortográfico em PT-BR no Arch Linux
[AJUDA] Problemas ao atualizar BIOS da Gigabyte B550M K rev. 1.1 — “RO... (2)
Impossível ativar audio 5.1 (1)
Erro na atualização dos pacotes (1)
Problema com Conexão Outlook via Firewall (OpenSUSE) com Internet Fibr... (3)