Advertisement
plarmi

RSP tkinter + OOP

May 2nd, 2024
678
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. from tkinter import *
  2. from random import randint
  3.  
  4. class Main(Frame):
  5.     def __init__(self, root):
  6.         super().__init__(root)
  7.         self.startUI(root)
  8.  
  9.     def startUI(self, root):
  10.         btn = Button(root, text="Камень", font=("Times New Roman", 15), command=lambda x=1: self.btn_click(x))
  11.         btn2 = Button(root, text="Ножницы", font=("Times New Roman", 15), command=lambda x=2: self.btn_click(x))
  12.         btn3 = Button(root, text="Бумага", font=("Times New Roman", 15), command=lambda x=3: self.btn_click(x))
  13.  
  14.         btn.place(x=10, y=100, width=120, height=50)
  15.         btn2.place(x=155, y=100, width=120, height=50)
  16.         btn3.place(x=300, y=100, width=120, height=50)
  17.  
  18.         self.lbl = Label(root, text="Начало игры!", bg="white", font=("Times New Roman", 21, "bold"))
  19.         self.lbl.place(x=150, y=25)
  20.  
  21.         self.win = self.drow = self.lose = 0
  22.  
  23.         self.lbl2 = Label(root, justify="left", font=("Times New Roman", 13), bg="white", text=f"Побед: {self.win}\n"
  24.                                                                                 f"Проигрышей: {self.lose}\n"
  25.                                                                                 f"Ничей: {self.drow}")
  26.         self.lbl2.place(x=5, y=5)
  27.  
  28.     def btn_click(self, choice):
  29.         # 1 - камень, 2 - ножницы, 3 - бумага
  30.         comp_choice = randint(1, 3)
  31.         print(comp_choice)
  32.  
  33.         if choice == comp_choice:
  34.             self.drow += 1
  35.             self.lbl.config(text="Ничья")
  36.         elif comp_choice == 1 and choice == 3 or comp_choice == 2 and choice == 1 or comp_choice == 3 and choice == 2:
  37.             self.win += 1
  38.             self.lbl.config(text="Победа")
  39.         else:
  40.             self.lose += 1
  41.             self.lbl.config(text="Проигрыш")
  42.  
  43.         self.lbl2.config(text=f"Побед: {self.win}\n"
  44.                               f"Проигрышей: {self.lose}\n"
  45.                               f"Ничей: {self.drow}")
  46.  
  47.         del comp_choice
  48.  
  49.  
  50.  
  51. window = Tk()
  52. window.geometry("430x160+200+200")
  53. window.title("Камень, ножницы, бумага")
  54. window.resizable(False, False)
  55. window.config(bg="white")
  56.  
  57. window2 = Tk()
  58. window2.geometry("430x160+200+200")
  59. window2.title("Камень, ножницы, бумага2")
  60. window2.resizable(False, False)
  61. window2.config(bg="white")
  62.  
  63. app = Main(window)
  64. app.pack()
  65.  
  66. app2 = Main(window2)
  67. app2.pack()
  68.  
  69. window.mainloop()
Advertisement
Comments
  • pepkoakra
    14 days (edited)
    # text 0.50 KB | 0 0
    1. Hello, Hello, https://bankonbet.casinologinaustralia.com in Australia has exceeded all my expectations for online gaming. The intuitive design of the platform makes it easy to navigate, whether you are a beginner or an experienced player. I especially like the variety of payment methods available, which ensures a hassle-free experience every time I deposit or withdraw funds. BankOnBet has really set the bar high for online casinos, and I'm very happy to be part of their community. I highly recommend this site.
Add Comment
Please, Sign In to add comment
Advertisement