eitaa logo
آموزش پایتون
62 دنبال‌کننده
244 عکس
106 ویدیو
52 فایل
ارتباط: https://eitaa.com/joinchat/956171922Cb501d5a32f لینک همین کانال: @LearnPythonIcy لینک کانال تلگرام: https://t.me/learnpythonicy
مشاهده در ایتا
دانلود
Tic-Tac-Toe Game In Python 🤩کی دوز بازی دوست داره؟ |
import tkinter as tk from tkinter import messagebox # Initialize the main window root = tk.Tk() root.title("Tic-Tac-Toe") root.configure(bg='lightblue') # Set background color # Variables to store the state of the game board = [' ' for _ in range(9)] player = 'X' scores = {'X': 0, 'O': 0} # Function to update the button text and board state def update_board(index, button): global player if board[index] == ' ': board[index] = player button.config(text=player, fg='blue' if player == 'X' else 'green', bg='white') if check_win(): messagebox.showinfo("Tic-Tac-Toe", f"Player {player} wins!") scores[player] += 1 reset_board() elif ' ' not in board: messagebox.showinfo("Tic-Tac-Toe", "No winner!") reset_board() else: player = 'O' if player == 'X' else 'X' # Function to check for a win def check_win(): win_conditions = [ (0, 1, 2), (3, 4, 5), (6, 7, 8), # Rows (0, 3, 6), (1, 4, 7), (2, 5, 8), # Columns (0, 4, 8), (2, 4, 6) # Diagonals ] for i, j, k in win_conditions: if board[i] == board[j] == board[k] != ' ': return True return False # Function to reset the board def reset_board(): global board, player board = [' ' for _ in range(9)] player = 'X' for button in buttons: button.config(text='', bg='lightgrey') # Function to show the scores when closing the game def on_closing(): messagebox.showinfo("Scores", f"Player X: {scores['X']} wins\nPlayer O: {scores['O']} wins") root.destroy() # Create buttons for the Tic-Tac-Toe board buttons = [] for i in range(9): button = tk.Button(root, text=' ', width=10, height=5, bg='lightgrey', command=lambda i=i: update_board(i, buttons[i])) button.grid(row=i//3, column=i%3, padx=5, pady=5) # Add padding for better spacing buttons.append(button) # Bind the closing event to the on_closing function root.protocol("WM_DELETE_WINDOW", on_closing) # Run the main loop root.mainloop() | | آموزش پایتون
1.6M حجم رسانه بالاست
مشاهده در ایتا
Morse Code Converter 🧑‍💻تبدیل کنندهٔ کد مورس |
Morse Code Converter 🔺تبدیل کننده کد مورس import tkinter as tk from tkinter import messagebox MORSE_CODE_DICT_ENGLISH = { 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--', 'Z': '--..', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', '6': '-....', '7': '--...', '8': '---..', '9': '----.', '0': '-----', ' ': '/' } MORSE_CODE_DICT_PERSIAN = { 'ا': '.-', 'ب': '-...', 'پ': '.--.', 'ت': '-', 'ث': '...-', 'ج': '.---', 'چ': '---.', 'ح': '....', 'خ': '----', 'د': '-..', 'ذ': '-...', 'ر': '.-.', 'ز': '--..', 'ژ': '--.-', 'س': '...', 'ش': '---', 'ص': '-.-.', 'ض': '-..-', 'ط': '-.-', 'ظ': '-.-.', 'ع': '--', 'غ': '-.-', 'ف': '..-.', 'ق': '--.-', 'ک': '-.-', 'گ': '--.', 'ل': '.-..', 'م': '--', 'ن': '-.', 'و': '.--', 'ه': '....', 'ی': '..', 'ء': '.', 'آ': '.-', 'ژ': '.-.-', 'چ': '--..', ' ': '/' } def text_to_morse(text, language): if language == "English": morse_dict = MORSE_CODE_DICT_ENGLISH elif language == "Persian": morse_dict = MORSE_CODE_DICT_PERSIAN morse_code = '' for char in text.upper(): morse_code += morse_dict.get(char, '?') + ' ' return morse_code.strip() def morse_to_text(morse_code, language): if language == "English": morse_dict = {v: k for k, v in MORSE_CODE_DICT_ENGLISH.items()} elif language == "Persian": morse_dict = {v: k for k, v in MORSE_CODE_DICT_PERSIAN.items()} words = morse_code.split(' ') translated_text = '' for word in words: letters = word.split(' ') for letter in letters: translated_text += morse_dict.get(letter, '?') translated_text += ' ' return translated_text.strip() def convert(): input_text = text_entry.get() conversion_type = conversion_var.get() if conversion_type == "English to Morse": result = text_to_morse(input_text, "English") elif conversion_type == "Persian to Morse": result = text_to_morse(input_text, "Persian") elif conversion_type == "Morse to English": result = morse_to_text(input_text, "English") elif conversion_type == "Morse to Persian": result = morse_to_text(input_text, "Persian") result_var.set(result) def copy_to_clipboard(): root.clipboard_clear() root.clipboard_append(result_var.get()) messagebox.showinfo("Copied", "The result has been copied to the clipboard") # Create the main window root = tk.Tk() root.title("Morse Code Converter") # Set background color root.configure(bg='') # Create widgets title_label = tk.Label(root, text="Morse Code Converter", font=("Helvetica", 16, "bold"), bg='', fg='') title_label.pack(pady=10) text_label = tk.Label(root, text="Enter Text or Morse Code:", bg='', fg='white') text_label.pack(pady=5) text_entry = tk.Entry(root, width=50) text_entry.pack(pady=5) conversion_var = tk.StringVar(value="English to Morse") conversion_menu = tk.OptionMenu(root, conversion_var, "English to Morse", "Persian to Morse", "Morse to English", "Morse to Persian") conversion_menu.pack(pady=10) convert_button = tk.Button(root, text="Convert", command=convert, bg='', fg='white') convert_button.pack(pady=10) copy_button = tk.Button(root, text="Copy to Clipboard", command=copy_to_clipboard, bg='', fg='white') copy_button.pack(pady=10) result_var = tk.StringVar() result_label = tk.Label(root, textvariable=result_var, bg='', fg='red', font=("Helvetica", 14)) result_label.pack(pady=10) # Run the main loop root.mainloop() |
2M حجم رسانه بالاست
مشاهده در ایتا
Creating a ToDo list in Python کارهای خود را با این اپلیکیشن ساده و کاربردی به راحتی مدیریت کنید! با چند کلیک وظایف خود را اضافه و حذف کنید و همیشه در مسیر هدف‌هایتان بمانید! 🎯💡 | | LearnPython