Mensagens

A mostrar mensagens de outubro, 2024

Valor Actual

from tkinter import * def calcular_valor_atual (): try : valor_passado = float (Valor_Passado.get()) taxa_inflacao = float (Taxa_Inflacao.get()) / 100 # Convertimos el % a decimal anos = int (Anos.get()) valor_atual = valor_passado * ( 1 + taxa_inflacao)**anos resultado.config( text = f"Valor Atual: { round (valor_atual , 2 ) } " ) except ValueError : resultado.config( text = "Erro: Verifique os valores inseridos!" ) root = Tk() root.geometry( "600x300" ) root.resizable( 0 , 0 ) root.config( bg = "#103030" ) root.title( "Valor Actual" ) titulo = Label( text = "Valor Actual" , font =( "Arial" , "35" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) titulo.place( relx = 0.28 , rely = 0.05 ) texto_sub1 = Label( text = "Valor Passado:" , font =( "Arial" , "15" , "bold" ) , bg = "#1030...

Doçura ou Travessura

from tkinter import * import random root = Tk() root.geometry( "400x200" ) root.resizable( 0 , 0 ) root.config( bg = "#103030" ) root.title( "Doçura ou Travessura" ) titulo = Label( text = "Doçura ou Travessura" , font =( "Arial" , "24" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) titulo.place( relx = 0.08 , rely = 0.05 ) def docura_ou_travessura ( event ): resultado = random.choice([ "doçura" , "travessura" ]) if resultado == "doçura" : mensagem = "Você ganhou um doce!" else : mensagem = "Travessura! \n Prepare-se para o susto!" texto_sub1.config( text =mensagem) but1 = Button( text = "Mostrar" , bd = 2 , bg = '#107db2' , fg = 'white' , font =( 'verdana' , 12 , 'bold' ) , command =docura_ou_travessura) but1.place( relx = 0.1 , rely = 0.8 , rel...

Barra de Progresso (usando Tkinter)

import tkinter as tk from tkinter import ttk import time import threading def start_loading (): progress_bar[ "value" ] = 0 for i in range ( 101 ): progress_bar[ "value" ] = i # Atualiza a barra de progresso percentage_label.config( text = f" { i } %" ) # Atualiza a porcentagem no label time.sleep( 0.05 ) # Simula o tempo de processamento root.update_idletasks() # Atualiza a interface # Configurações da janela root = tk.Tk() root.title( "Loading com Barra de Progresso" ) root.geometry( "300x200" ) # Label principal label = tk.Label(root , text = "Carregando..." ) label.pack( pady = 10 ) # Barra de Progresso progress_bar = ttk.Progressbar(root , orient = "horizontal" , length = 200 , mode = "determinate" ) progress_bar.pack( pady = 10 ) # Label para a porcentagem percentage_label = tk.Label(root , text = "0%" ) percentage_label.pack() # Botão para iniciar...

Alarme de Aniversários

from datetime import datetime from tkinter import * # Dados de datas de nascimento datas_nascimento = { "António Silva" : [ "2020-12-01" ] , "Ana Magalhães" : [ "1957-09-13" ] , "Júlia Machado" : [ "1960-05-06" ] , "Tiago Silva" : [ "1975-04-06" ] , "Rui Noveira" : [ "1968-05-15" ] , "Mariana Mortágua" : [ "1945-07-15" ] , "Marisa Matias" : [ "1947-07-15" ] , "Joana Mortágua" : [ "1978-07-15" ] , "Rita Vieira" : [ "1984-07-17" ] } # Função para calcular a idade def calcular_idade (data_nascimento): hoje = datetime.today() data_formatada = datetime.strptime(data_nascimento[ 0 ] , "%Y-%m-%d" ) idade = hoje.year - data_formatada.year if (hoje.month , hoje.day) < (data_formatada.month , data_formatada.day): idade -= 1 return idade # Conf...

Mostrar as Tarefas com Galinhas

from datetime import datetime from tkinter import * tarefas_semanal = { "Segunda-feira" : "Limpeza Completa do Galinheiro" , "Terça-feira" : "Verificação de Parasitas" , "Quarta-feira" : "Inspeção de Cerca e Proteção Contra Predadores" , "Quinta-feira" : "Reforçar Suplementação Alimentar" , "Sexta-feira" : "Avaliação de Peso e Condição das Galinhas" , "Sábado" : "Revisão Geral e Ajustes" , "Domingo" : "Dia de Descanso para Galinhas" } def mostrar_tarefa_hoje (): hoje = datetime.now().strftime( "%A" ) if hoje == "Monday" : hoje = "Segunda-feira" elif hoje == "Tuesday" : hoje = "Terça-feira" elif hoje == "Wednesday" : hoje = "Quarta-feira" elif hoje == "Thursday" : hoje = "Quinta-feira...

Calcular os dias da mudança de Hora

from tkinter import * from datetime import date , timedelta # Configuração da janela root = Tk() root.geometry( "700x300" ) root.resizable( 0 , 0 ) root.config( bg = "#103030" ) root.title( "Calcular os dias da mudança de Hora" ) # Título titulo = Label( text = "Calcular os dias da mudança de Hora" , font =( "Arial" , "26" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) titulo.place( relx = 0.08 , rely = 0.05 ) # Texto e entrada para o ano texto_sub1 = Label( text = "Ano :" , font =( "Arial" , "15" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) texto_sub1.place( relx = 0.26 , rely = 0.25 ) Ano = StringVar() Ano_entrada = Entry( textvariable =Ano , font =( "Arial" , "12" , "bold" ) , bg = "white" , fg = "blue" , justif...

Registar Sexo

escolha = True while escolha == True : sexo = str ( input ( "Informe o seu sexo:[M/F] " )).strip().upper()[ 0 ] if sexo not in "MF" : print ( "Informação Errada!" ) elif sexo == "M" : print ( "O sexo registrado foi: Masculino." ) else : print ( "O sexo registrado foi: Feminino." ) # VersãoTkinter from tkinter import * root = Tk() root.geometry( "400x400" ) root.resizable( 0 , 0 ) root.config( bg = "#103030" ) root.title( "Escolha de Sexo" ) titulo = Label( text = "Escolha de Sexo" , font =( "Arial" , "28" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) titulo.place( relx = 0.08 , rely = 0.05 ) def app (): v = sexo.get() if v == 1 : resultado_texto.config( text = "O sexo registrado foi: Masculino." ) elif v == 2 : resultado_texto.config( text = ...

Simulador de dado de cores

import random import time dado_cores = [ "Azul" , "Amarelo" , "Vermelho" , "Verde" , "Roxo" , "Cinza" ] sorteios = True while sorteios == True : cor_sorteada = random.choice(dado_cores) time.sleep( 2 ) print ( f"Cor sorteada: { cor_sorteada } " ) if cor_sorteada == "Vermelho" : print ( "Avança uma casa." ) time.sleep( 2 ) elif cor_sorteada == "Azul" : print ( "Avança 5 casas." ) time.sleep( 2 ) elif cor_sorteada == "Amarelo" : print ( "Recua 2 casas." ) time.sleep( 2 ) elif cor_sorteada == "Verde" : print ( "Passa a vez a outro jogador." ) elif cor_sorteada == "Roxo" : print ( "Tira uma carta." ) time.sleep( 2 ) else : print ( "Fica uma vez sem jogar ." ) time.sleep( 2 )

Valor do Jogador (usando Tkinter)

from tkinter import * class Tooltip: def __init__ ( self , widget , text): self .widget = widget self .text = text self .tooltip_window = None self .widget.bind( "<Enter>" , self .show_tooltip) self .widget.bind( "<Leave>" , self .hide_tooltip) def show_tooltip ( self , event=None ): if self .tooltip_window is not None : return x , y , _ , _ = self .widget.bbox( "insert" ) x += self .widget.winfo_rootx() + 25 y += self .widget.winfo_rooty() + 25 self .tooltip_window = Toplevel( self .widget) self .tooltip_window.wm_overrideredirect( True ) self .tooltip_window.wm_geometry( f"+ { x } + { y } " ) label = Label( self .tooltip_window , text = self .text , background = "lightyellow" , borderwidth = 1 , relief = "solid" ) label.pack() def hide_tooltip ( self , event=None ): if se...

Custo Total da Acção (usando Tkinter)

from tkinter import * import requests from bs4 import BeautifulSoup class Tooltip: def __init__ ( self , widget , text): self .widget = widget self .text = text self .tooltip_window = None self .widget.bind( "<Enter>" , self .show_tooltip) self .widget.bind( "<Leave>" , self .hide_tooltip) def show_tooltip ( self , event=None ): if self .tooltip_window is not None : return x , y , _ , _ = self .widget.bbox( "insert" ) x += self .widget.winfo_rootx() + 25 y += self .widget.winfo_rooty() + 25 self .tooltip_window = Toplevel( self .widget) self .tooltip_window.wm_overrideredirect( True ) self .tooltip_window.wm_geometry( f"+ { x } + { y } " ) label = Label( self .tooltip_window , text = self .text , background = "lightyellow" , borderwidth = 1 , relief = "solid" ) label.pack() def hid...