Mensagens

A mostrar mensagens de julho, 2022

Frase Inversa

from tkinter import * root = Tk() root.title( 'Inverso da frase' ) root.geometry( '400x200' ) root.resizable( False,False ) root.configure( background = '#eaeef5' ) def mostrar (): frase = frase_entry.get() palavra_inversa = "" for x in frase: palavra_inversa = x + palavra_inversa resultado[ 'text' ] = palavra_inversa frase_lb = Label( text = " Escreva a Frase " , font =( "Helvetica" , '14' , 'bold' ) , bg = '#78c8c0' , fg = '#0a0fc9' ) frase_lb.place( relx = 0.3 , rely = 0.05 ) frase_entry = Entry(root , justify = 'center' ) frase_entry.place( relx = 0.2 , rely = 0.3 , relwidth = 0.6 ) button = Button( text = 'Mostrar' , bg = '#0a0fc9' , fg = '#78c8c0' , font =( 'Arial' , '13' ) , command =mostrar) button.place( relx = 0.45 ,...

discord (criar um muito simples bot)

Token = "Coloque o seuToken " import discord class MyClient(discord.Client): async def on_ready ( self ): print ( 'Logged on as' , self .user) async def on_message ( self , message): # don't respond to ourselves if message.author == self .user: return if message.content == 'Olá' : await message.channel.send( 'Olá. Espero que esteja correr bem.' ) client = MyClient() client.run(Token) # Outro Token = "Coloque o seuToken " import discord import os class MyClient(discord.Client): async def on_ready ( self ): print ( 'Logged on as {0}!' .format( self .user)) async def on_message ( self , message): print ( 'Message from {0.author}: {0.content}' .format(message)) if message.content == '?regras' : await message.channel.send ( f' { message.author.name } as regras do servidor' ...

Semáforo da passadeira

import datetime import time escolha = True while escolha: dado1 = 1 dado2 = 2 now = datetime.datetime.now() b = int (now.strftime( "%H" )) print (b) time.sleep( 1 ) c = b if c >= 8 and c <= 16 : print ( " \033 [1;32m Sinal Verde \033 [m" ) time.sleep( 10 ) print ( " \033 [1;33m Sinal Amarelo \033 [m" ) time.sleep( 2 ) print ( " \033 [1;31m Sinal Vermelho \033 [m" ) a = time.sleep( 120 ) print (a) else : print ( " \033 [1;31m Sinal Vermelho \033 [m" ) input ( " \n Carregue para mudar para verde..." ) print ( " \033 [1;32m Sinal Verde \033 [m" ) time.sleep( 10 ) print ( " \033 [1;33m Sinal Amarelo \033 [m" ) time.sleep( 2 ) print ( " \033 [1;31m Sinal Vermelho \033 [m" )

Fuso Horário (usando tkinter )

from tkinter import * from datetime import datetime import pytz root = Tk() root.title( "Fuso Horário" ) root.geometry( "500x250" ) root.resizable( False,False ) def times (): timezone = pytz.timezone( 'America/New_York' ) hora_local = datetime.now(timezone) tempo_actual = hora_local.strftime( '%H:%M:%S' ) horas1.config( text =tempo_actual) horas1.after( 200 , times) timezone1 = pytz.timezone( 'Africa/Luanda' ) hora_local1 = datetime.now(timezone1) tempo_actual1 = hora_local1.strftime( '%H:%M:%S' ) horas2.config( text =tempo_actual1) horas2.after( 200 , times) timezone2 = pytz.timezone( 'Europe/Luxembourg' ) hora_local2 = datetime.now(timezone2) tempo_actual2 = hora_local2.strftime( '%H:%M:%S' ) horas3.config( text =tempo_actual2) horas3.after( 200 , times) timezone3 = pytz.timezone( 'Asia/Macau' ) hora_local3 = datetime.now(timezone3) temp...

Python para iniciantes

face = "O rating do Facebook é de " rating = 3.5 fg_rating = str (rating) fg = face + ' ' + fg_rating print (fg)

Exemplo do Tkinter usando Butões

from tkinter import * from tkinter import messagebox root = Tk() root.geometry( '300x200' ) root.resizable( False,False ) root.title( "Exemplo Tkinter Butões" ) def bnorte (): messagebox.showinfo( 'Butão Norte' , 'O Norte fica em cima' ) def bsul (): messagebox.showinfo( 'Butão Sul' , 'O Sul fica em baixo' ) def beste (): messagebox.showinfo( 'Butão Este' , 'O Este fica lado direito' ) def boste (): messagebox.showinfo( 'Butão Oste' , 'O Oste fica lado esquerdo' ) norte = Button( text = 'Norte' , font =( "verdana" , 10 , "bold" ) , bg = "blue" , fg = "white" , command =bnorte) norte.place( relx = 0.35 , rely = 0.05 , relwidth = 0.25 , relheight = 0.15 ) sul = Button( text = 'Sul' , font =( "verdana" , 10 , "bold" ) , bg = "green" , fg = "white" , command =bsul) s...

Jogo de Escala Músical

escala =[ 'Dó' , 'Ré' , 'Mi' , 'Fá' , 'Sol' , 'Lá' , 'Sí' , 'Dó' ] respostascertas = 0 cont = 0 pergunta = 1 escolha= True while escolha: print ( " \t Escala Músical " ) print ( """ 1.Escala Músical 2.Exit/Quit/Saída """ ) escolha= input ( "Por favor, escolha a opção: " ) if escolha == "1" : while cont != 8 : resposta = str ( input ( f"Qual é a escala músical { pergunta } º? " )) if resposta == escala[cont]: respostascertas = respostascertas + 1 print ( f"Tem { respostascertas } respostas certas em 8." ) else : print ( f"Tem { respostascertas } respostas certas em 8." ) cont = cont + 1 pergunta = 1 + pergunta elif escolha == "2" : print ( "Fim do programa!"...

Bandeira da Polónia| flaga Polski

from tkinter import * root = Tk() root.title( "Bandeira da Polónia" ) root.resizable( False,False ) frame_cima = Frame( bg = "white" , height = 70 , width = 400 ) frame_baixo = Frame( bg = 'red' , height = 70 , width = 400 ) frame_cima.pack() frame_baixo.pack() mainloop()

Mensagem do nome

from tkinter import * def accao (): nome = entradaNome.get() resultado[ 'text' ] = "Bem-vinda, " + nome + " !" root = Tk() root.geometry( "375x150" ) root.resizable( False,False ) nome_lb = Label(root , text = "Escreva o seu nome : " ) nome_lb.place( relx = 0.05 , rely = 0.1 ) entradaNome = Entry( justify = 'center' ) entradaNome.place( relx = 0.45 , rely = 0.13 ) # btn = Button(root , text = "Validar" , width = 25 , command = accao) btn.place( relx = 0.25 , rely = 0.35 ) resultado = Label(root , text = '...........' ) resultado.place( relx = 0.25 , rely = 0.6 )

Lista de tarefas (muito simples usando Checkbutton )

import tkinter cont = 0 window_main = tkinter.Tk( className = 'Lista de tarefas' ) window_main.geometry( "450x250" ) window_main.resizable( False,False ) check_1 = tkinter.IntVar() check_2 = tkinter.IntVar() check_3 = tkinter.IntVar() def check1Clicked (): if check_1.get(): global cont cont = cont + 1 resultado_lb[ 'text' ] = cont else : cont = cont - 1 resultado_lb[ 'text' ] = cont def check2Clicked (): if check_2.get(): global cont cont = cont + 1 resultado_lb[ 'text' ] = cont else : cont = cont - 1 resultado_lb[ 'text' ] = cont def check3Clicked (): if check_3.get(): global cont cont = cont + 1 resultado_lb[ 'text' ] = cont else : cont = cont - 1 resultado_lb[ 'text' ] = cont check_but_1 = tkinter.Checkbutton(window_main , text = 'Listening to Music' , ...

Verificar se o número é uma raiz quadrado

from tkinter import * root = Tk() def butaofuncao (): N = int (entrada_numero.get()) j = 0 for i in range ( 0 , N): if (i ** 2 == N): j = i break if j > 0 : texto[ 'text' ] = str (N) + " é uma raiz quadrada perfeita" + str (N) + " = " + str (j) + " ^ 2" else : texto[ 'text' ] = str (N) + " não é uma raiz quadrada perceita ! " root.title( 'Python Tkinter' ) root.geometry( "400x170" ) root.resizable( False,False ) l_numero = Label( text = "Digite o número inteiro: " ) l_numero.place( relx = 0.1 , rely = 0.05 ) entrada_numero = Entry( justify = 'center' ) entrada_numero.place( relx = 0.45 , rely = 0.05 , relwidth = 0.2 ) texto = Label( text = '...........' ) texto.place( relx = 0.35 , rely = 0.55 ) # butao = Button(root , text = "Validar" , command =butaofuncao) butao.place( relx = 0.4 , rely = 0.3 , relwidth =...

Intersecção de lista

list1 = [ 5 , 2 , 10 , 4 , 6 , 9 ] print ( "Primeira Lista ordenada:" , sorted (list1)) list2 = [ 2 , 4 , 13 , 8 , 10 , 14 ] print ( "Segunda Lista ordenada:" , sorted (list2)) set1 = set (list1) set2 = set (list2) novalista = list (set1.intersection(set2)) print ( "Intersecção da lista é de :" , sorted (novalista))

toma de medicamento (Listas e Dicionário e uma maneira muito simples)

import datetime nomemeidcamentos = [] hora = [] numero_medicamentos = int ( input ( "Quantos número de medicamentos: " )) cont = 0 dic = {} while numero_medicamentos != cont: nome_medicamento = str ( input ( "Digite o nome do medicamento: " )) nomemeidcamentos.append(nome_medicamento) hora_toma = int ( input ( "Digite a hora da toma: " )) hora.append(hora_toma) cont = cont+ 1 #print(nomemeidcamentos) #print(hora) # Criar dicionáro dict = {} for i , j in zip (nomemeidcamentos , hora): dict[i] = j print (dict) escolha = True while escolha: now = datetime.datetime.now() b = int (now.strftime( "%H" )) for value in dict.values(): if value == b: key_list = list (dict.keys()) val_list = list (dict.values()) position = val_list.index(value) print ( f'Está na hora de tomar { key_list[position] } ' ) input ( " \n Carregue enter para confirm...

Tempo continuo

import datetime import time escolha = True while escolha: now = datetime.datetime.now() print (now.strftime( "%H:%M:%S" )) time.sleep( 1 ) # Tempo Fuzo horário from datetime import datetime import pytz import time escolha = True while escolha: timezone = pytz.timezone( 'America/New_York' ) date_string_with_specific_timezone = datetime.utcnow().astimezone( tz =timezone).strftime( '%H:%M:%S' ) time.sleep( 1 ) print (date_string_with_specific_timezone)

Votação do parlamento

ps = 120 psd = 77 il = 8 pcp = 6 be = 5 pan = 1 l = 1 ch = 12 votacaototalfavor = 0 votacaototacontra = 0 votacaoabstenção = 0 escolha= True while escolha: vps = str ( input ( "Votação do PS: Favor [F], Contra [C] ou Abstenção [A]: " "" )).lower() if vps == 'f' : votacaototalfavor = ps + votacaototalfavor break elif vps == 'c' : votacaototacontra = ps + votacaototacontra break elif vps == 'a' : votacaoabstenção = ps + votacaoabstenção break else : print ( " \n Escolha não válida. \n Tente outra vez." ) escolha1= True while escolha1: vpsd = str ( input ( "Votação do PSD: Favor [F], Contra [C] ou Abstenção [A]: " "" )).lower() if vpsd == 'f' : votacaototalfavor = psd + votacaototalfavor break elif vpsd == 'c' : votacaototacontra = psd + votacao...

aceleração gravitacional

# aceleração gravitacional gc = float ( input ( 'Constante Gravitacional: ' )) m = float ( input ( 'Massa da fonte de campo: ' )) r = float ( input ( 'Distância entre as duas massas pontuais: ' )) re = float ( input ( 'Vetor unitário direcionado da fonte de' ' campo para a massa de amostra menor: ' )) gp = (gc*m)/ pow (r , 2 ) g = round ((gp*re) , 2 ) print ( f"Aceleração gravitacional é de { g } " )

Adicionar horas para toma de Medicamentos(usando tkinter)

from tkinter import * root =Tk() class app(): def __init__ ( self ): self .root = root self .janela() self .desenvolverdor() root.mainloop() def janela ( self ): self .root.title( "Adicionar horas para toma de Medicamentos" ) self .root.geometry( "300x200" ) self .root.configure( background = '#d9f1ff' ) self .root.resizable( False, False ) def desenvolverdor ( self ): self .horas_adicionar = IntVar() self .horas_adicionar_lb = Label( text = " Horas Adiconar: " , font =( "Helvetica" , '10' )) self .horas_adicionar_lb.place( relx = 0.05 , rely = 0.05 ) self .horas_adicionar_entry = Entry( textvariable = self .horas_adicionar , justify = 'center' ) self .horas_adicionar_entry.place( relx = 0.5 , rely = 0.05 , relwidth = 0.2 ) self .horas_inicial = IntVar() sel...

Calcular a próxima toma do medicamento

horas_adicionar = int ( input ( "Digite quantas horas deseja adiconar: " )) hora_inicial = int ( input ( "Hora inicial: " )) hora_final = horas_adicionar + hora_inicial if hora_final <= 23 : print ( f'A hora da próxima toma é às { hora_final } horas.' ) elif hora_final == 24 : int ( f'A hora da próxima toma é às 0 horas' ) else : hora_final = horas_adicionar + hora_inicial - 24 print ( f'A hora da próxima toma é às { hora_final } horas.' )

Alarme para tomar medicamentos (usando Tkinter)

from tkinter import * import datetime import time from tkinter import messagebox def med (set_alarm_timer): while True : time.sleep( 1 ) actual_time = datetime.datetime.now() cur_time = actual_time.strftime( "%H:%M:%S" ) cur_date = actual_time.strftime( "%d/%m/%Y" ) if cur_time == set_alarm_timer: messagebox.showinfo( "Atenção" , "Hora de tomar medicamentos" ) break def tomar_medacamentos (): hora_tomar = f" { hora.get() } : { min.get() } : { sec.get() } " med(hora_tomar) window = Tk() window.title( "Tomar Medicamentos" ) window.geometry( "400x160" ) window.config( bg = "#922B21" ) window.resizable( False,False ) addTime = Label(window , text = " H Min " "Sec" , font = 60 , fg = "white" , bg = "black" ).place( x = ...

Comparar duas listas

a = [ 1 , 25 , 45 , 98 , 79 , 75 ] b = [ 75 , 45 , 2 , 79 , 25 , 98 ] c = list ( set (b).intersection(a)) if (( len (b)== len (a))) & ( len (c)== len (a)) : print ( "Tudo igual" ) else : print ( "Tem diferenças" )

Lotofácil (muito simples)

import random import time numeros =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 ] print ( "Vamos baralhar" ) time.sleep( 2 ) random.shuffle(numeros) print ( f"Resultado do sorteio " , sorted (numeros[ 0 : 15 ]))

Login (muito muito simples Tkinter )

from tkinter import * root = Tk() def mostrar (): if entrada[ 'show' ] == '*' : entrada[ 'show' ] = '' else : entrada[ 'show' ] = '*' root.geometry( '400x100' ) root.resizable( False,False ) root.title( "Login exemple" ) root.configure( background = '#eaeef5' ) a = Label( text = 'Palavra-Passe: ' , fg = 'blue' , bg = '#eaeef5' , font =( 'Arial' , '14' , 'bold' )) a.place( relx = 0.05 , rely = 0.1 ) passe = StringVar() entrada = Entry( textvariable =passe , justify = 'center' , show = '*' ) entrada.place( relx = 0.45 , rely = 0.13 ) mostrar_pass= Checkbutton( text = "Mostrar" , bg = '#ddd' , fg = 'black' , font =( 'verdana' , 14 ) , command =mostrar) mostrar_pass.place( relx = 0.1 , rely = 0.45 ) root.mainloop()

Calcular cm em pés ou cm em polgadas

# Pés cm= int ( input ( "Insira a altura em centímetros:" )) Pé = 0.0328 *cm print ( "O comprimento em pés" , round (Pé , 2 ))     # Polegada cm= int ( input ( "Insira a altura em centímetros:" )) polgada= 0.394 *cm print ( "O comprimento em polgadas" , round (polgada , 2 ))

Filmes

import imdb ia = imdb.IMDb() name = "The Lives of Others" search = ia.search_movie(name) print (search)

Horas para ir à praia usando Tkinter e Canvas

from tkinter import * root =Tk() class app(): def __init__ ( self ): self .root = root self .janela() self .desenvolver() root.mainloop() def janela ( self ): self .root.title( "Horas de ir para a Praia" ) self .root.geometry( "300x250" ) self .root.configure( background = 'Gray' ) self .root.resizable( False, False ) def desenvolver ( self ): self .tempo = IntVar() self .tempo_lb = Label( text = " Hora a validar: " , font =( "Helvetica" , '10' )) self .tempo_lb.place( relx = 0.15 , rely = 0.15 ) self .tempo_entry = Entry( textvariable = self .tempo , justify = 'center' ) self .tempo_entry.place( relx = 0.55 , rely = 0.15 , relwidth = 0.2 ) # Butão de calcular # self .bt_calcular = Button( text = "Mostrar" , bd = 2 , ...