◀️اینجا با تمرین و چالش با هم پایتون رو یاد می گیریم
⏮بانک اطلاعاتی پایتون
پروژه / code/ cheat sheet
+ویدیوهای آموزشی
+کتابهای پایتون
تبلیغات:
@alloadv
🔁ادمین :
@maryam3771
Post #154
6.59K
- 🤷♂ 9
- 👍 5
- 🤡 1
پا @python4all_pro
Showing posts older than #156 · Back to latest


with open("hello.txt", "w+") as f:
f.write("Hello World")
f.seek(0)
print(f.read())from tkinter import *
import random
root = Tk()
# Defining the size, width=400, height=240
root.geometry('400x240')
# Title
root.title('Love Calculator❤️❤️')
def calculate_love():
# value will contain digits between 0-9
st = '0123456789'
# result will be in double digits
digit = 2
temp = "".join(random.sample(st, digit))
result.config(text=temp)
# Heading on Top
heading = Label(root, text='Love Calculator????')
heading.pack()
# Slot/input for the first name
slot1 = Label(root, text="Enter Your Name:")
slot1.pack()
name1 = Entry(root, border=5)
name1.pack()
# Slot/input for the partner name
slot2 = Label(root, text="Enter Your Curse Name:")
slot2.pack()
name2 = Entry(root, border=5)
name2.pack()
bt = Button(root, text="Calculate", height=1,
width=7, command=calculate_love)
bt.pack()
# Text on result slot
result = Label(root, text='Love Percentage between both of You:')
result.pack()
# Starting the GUI
root.mainloop()

پایتون | Data Science | Machine Learning 🎁 تبریک تولد با استفاده از کد پایتون #code 🆔 @Python4all_pro
python
import turtle import random import time from pygame import mixer # Adding music is optional as per your choice. mixer.init() mixer.music.load("happy-birthday-song.mp3") # add your music file name or path # sets background bg = turtle.Screen() bg.bgcolor("black") mixer.music.play() # Bottom Line 1 turtle.penup() turtle.goto(-170, -180) turtle.color("white") turtle.pendown() turtle.forward(350) # Mid Line 2 turtle.penup() turtle.goto(-160, -150) turtle.color("white") turtle.pendown() turtle.forward(300) # First Line 3 turtle.penup() turtle.goto(-150, -120) turtle.color("white") turtle.pendown() turtle.forward(250) bg.bgcolor("lightgreen") # Cake turtle.penup() turtle.goto(-100, -100) turtle.color("white") turtle.begin_fill() turtle.pendown() turtle.forward(140) turtle.left(90) turtle.forward(95) turtle.left(90) turtle.forward(140) turtle.left(90) turtle.forward(95) turtle.end_fill() bg.bgcolor("lightblue") # Candles turtle.penup() turtle.goto(-90, 0) turtle.color("red") turtle.left(180) turtle.pendown() turtle.forward(20) turtle.penup() turtle.goto(-60, 0) turtle.color("blue") turtle.pendown() turtle.forward(20) turtle.penup() turtle.goto(-30, 0) turtle.color("yellow") turtle.pendown() turtle.forward(20) turtle.penup() turtle.goto(0, 0) turtle.color("green") turtle.pendown() turtle.forward(20) turtle.penup() turtle.goto(30, 0) turtle.color("purple") turtle.pendown() turtle.forward(20) bg.bgcolor("orange") # Decoration colors = ["red", "orange", "yellow", "green", "blue", "purple", "black"] turtle.penup() turtle.goto(-40, -50) turtle.pendown() for each_color in colors: angle = 360 / len(colors) turtle.color(each_color) turtle.circle(10) turtle.right(angle) turtle.forward(10) bg.bgcolor("red") # Happy Birthday message with bouncing animation turtle.penup() turtle.goto(-150, 50) turtle.color("yellow") turtle.pendown() # ENTER YOUR NAME IN THE NAME PLACE turtle.write(arg=f"Happy Birthday CodeWithRandom!", align="center", font=("jokerman", 20, "normal")) time.sleep(1.5) # Bouncing Animation for _ in range(7): turtle.penup() turtle.goto(-150, 50) turtle.pendown() turtle.clear() turtle.penup() turtle.goto(-150, 50 - _ * 10) turtle.pendown() turtle.write(arg=f"Happy Birthday CodeWithRandom!", align="left", font=("jokerman", 20, "normal")) time.sleep(0.5) turtle.done()