0
0 комментариев

[apcode language=»python»]

from tkinter import *
from tkinter import messagebox as mb
class Main:
    g="#808080"
    p="#808080"
    flag=0
    podshet = 0
    s="0"
    g1=["25","45","65","Желтый","Красный","Синий"]
    a1=["20+25=?","Какие цвета есть в флаге Украины?","Какого цвета красное яблоко?"]
    a_3_1="красного"
    g2 = ["Китай", "Украина", "Франция", "ІПСЕ", "ІПСА", "ІПСУ"]
    a2 = ["Самая большая страна в Европе", "Как не правильно?", "Какой герб Ураины?"]
    a_3_2 = "трезубец"
    okno = 0
     def __init__(self):
        mainmenu = Menu(root)
        root.resizable(False, False)
        root.config(menu=mainmenu)
        allmenu = Menu(mainmenu, tearoff=0)
        mainmenu.add_command(label='Адмін',command=self.admin)
        mainmenu.add_command(label='About',command=self.about)
         test1 = Button(root, width=20, height=3, text="Test 1", font=("Arial", 12),command=self.test1)
        test2 = Button(root, width=20, height=3, text="Test 2", font=("Arial", 12),command=self.test2)
        test1.grid(row=1, column=0, columnspan=1)
        test2.grid(row=2, column=0, columnspan=1)
        root.config(menu=mainmenu)
    def test1(self):
        self.win2 = Toplevel(root)
        self.win2.title("Test 1")
        self.win2.config(bd=20, bg='#808080')
        self.okno = 1
        if self.s == "1069":
            self.reas = Button(self.win2, width=20, text="Редактировать", font=("Arial", 10), command=self.Reas)
            self.reas.grid(row=0, column=0, sticky=E, padx=15, pady=10, )
            self.p = "#008000"
         t_1 = Label(self.win2, text=self.a1[0], font=("White", 20), background=self.g)
        t_1.grid(row=0, column=1, columnspan=1, sticky=W)
        self.Radio = IntVar()
        self.Radio.set(0)
        self.с_1_1 = Radiobutton(self.win2,text=self.g1[0], variable=self.Radio, value=0, background=self.g)
        self.с_1_2 = Radiobutton(self.win2,text=self.g1[1], variable=self.Radio, value=1, background=self.p)
        self.с_1_3 = Radiobutton(self.win2,text=self.g1[2], variable=self.Radio, value=2, background=self.g)
        self.с_1_1.grid(row=1, column=0,padx=15, pady=10, columnspan=1, sticky=W)
        self.с_1_2.grid(row=2, column=0,padx=15, pady=10, columnspan=1, sticky=W)
        self.с_1_3.grid(row=3, column=0, padx=15, pady=10,columnspan=1, sticky=W)
        self.t_2 = Label(self.win2, text=self.a1[1], font=("Arial", 20), background=self.g)
        self.t_2.grid(row=4, column=1, columnspan=1, sticky=W)
        self.Check1 = BooleanVar()
        self.Check1.set(0)
        self.с_2_1 = Checkbutton(self.win2,text=self.g1[3], variable=self.Check1, onvalue=1, offvalue=0, background=self.p)
        self.с_2_1.grid(row=5, column=0,padx=15, pady=10, columnspan=1, sticky=W)
        self.Check2 = BooleanVar()
        self.Check2.set(0)
        self.с_2_2 = Checkbutton(self.win2,text=self.g1[4], variable=self.Check2, onvalue=1, offvalue=0, background=self.g)
        self.с_2_2.grid(row=6, column=0,padx=15, pady=10, columnspan=1, sticky=W)
        self.Check3 = BooleanVar()
        self.Check3.set(0)
        self.с_2_3 = Checkbutton(self.win2,text=self.g1[5], variable=self.Check3, onvalue=1, offvalue=0, background=self.p)
        self.с_2_3.grid(row=7, column=0,padx=15, pady=10, columnspan=1, sticky=W)
        self.t_3 = Label(self.win2, text=self.a1[2], font=("Arial", 20), background=self.g)
        self.t_3.grid(row=8, column=1, columnspan=1, sticky=W)
        self.c_3_1 = Entry(self.win2, width=20,font=("Arial", 10))
        self.c_3_1.grid(row=9, column=0, sticky=W,padx=15, pady=10,)
        self.c_4 = Button(self.win2, width=20, text="Завершити", font=("Arial", 10), command=self.Ans_test1)
        self.c_4.grid(row=10, column=0, sticky=E,padx=15, pady=10,)
        if self.flag==2:
            self.t_1_reas = Entry(self.win2, width=30, )
            self.t_1_reas.grid(row=0, column=2, sticky=W, padx=15, pady=10, )
            self.c_1_1_reas = Entry(self.win2, width=30, )
            self.c_1_1_reas.grid(row=1, column=1, sticky=W, padx=15, pady=10, )
            self.c_1_2_reas = Entry(self.win2, width=30, )
            self.c_1_2_reas.grid(row=2, column=1, sticky=W, padx=15, pady=10, )
            self.c_1_3_reas = Entry(self.win2, width=30, )
            self.c_1_3_reas.grid(row=3, column=1, sticky=W, padx=15, pady=10, )
            self.t_2_reas = Entry(self.win2, width=30, )
            self.t_2_reas.grid(row=4, column=2, sticky=W, padx=15, pady=10, )
            self.c_2_1_reas = Entry(self.win2, width=30, )
            self.c_2_1_reas.grid(row=5, column=1, sticky=W, padx=15, pady=10, )
            self.c_2_2_reas = Entry(self.win2, width=30, )
            self.c_2_2_reas.grid(row=6, column=1, sticky=W, padx=15, pady=10, )
            self.c_2_3_reas = Entry(self.win2, width=30, )
            self.c_2_3_reas.grid(row=7, column=1, sticky=W, padx=15, pady=10, )
            self.t_3_reas = Entry(self.win2, width=30, )
            self.t_3_reas.grid(row=8, column=2, sticky=W, padx=15, pady=10, )
            self.c_3_1_reas = Entry(self.win2, width=30, )
            self.c_3_1_reas.grid(row=9, column=1, sticky=W, padx=15, pady=10, )
            self.edit = Button(self.win2, width=20, text="Сохранить", font=("Arial", 10), command=self.Edit)
            self.edit.grid(row=10, column=2, sticky=E, padx=15, pady=10, )
          if self.flag==1:
            self.aa = Label(self.win2, text="Твой ответ -{},а правильный красного".format(self.A), font=("Arial", 10),background=self.g)
            self.aa.grid(row=12, column=0, columnspan=1, sticky=W)
            self.ab = Label(self.win2, text="Твоя оценка - {} из 3".format(self.podshet), font=("Arial", 10),background=self.g)
            self.ab.grid(row=13, column=0, columnspan=1, sticky=W)
            self.podshet=0
            self.p = "#808080"
            self.flag = 0
           def test2(self):
        self.win3 = Toplevel(root)
        self.win3.title("Test 2")
        self.win3.config(bd=20, bg='#808080')
        self.okno = 2
        if self.s == "1069":
            self.reas = Button(self.win3, width=20, text="Редактировать", font=("Arial", 10), command=self.Reas)
            self.reas.grid(row=0, column=0, sticky=E, padx=15, pady=10, )
            self.p = "#008000"
         t_1 = Label(self.win3, text=self.a2[0], font=("White", 20), background=self.g)
        t_1.grid(row=0, column=1, columnspan=1, sticky=W)
        self.Radio = IntVar()
        self.Radio.set(0)
        self.с_1_1 = Radiobutton(self.win3, text=self.g2[0], variable=self.Radio, value=0, background=self.g)
        self.с_1_2 = Radiobutton(self.win3, text=self.g2[1], variable=self.Radio, value=1, background=self.p)
        self.с_1_3 = Radiobutton(self.win3, text=self.g2[2], variable=self.Radio, value=2, background=self.g)
        self.с_1_1.grid(row=1, column=0, padx=15, pady=10, columnspan=1, sticky=W)
        self.с_1_2.grid(row=2, column=0, padx=15, pady=10, columnspan=1, sticky=W)
        self.с_1_3.grid(row=3, column=0, padx=15, pady=10, columnspan=1, sticky=W)
        self.t_2 = Label(self.win3, text=self.a2[1], font=("Arial", 20), background=self.g)
        self.t_2.grid(row=4, column=1, columnspan=1, sticky=W)
        self.Check1 = BooleanVar()
        self.Check1.set(0)
        self.с_2_1 = Checkbutton(self.win3, text=self.g2[3], variable=self.Check1, onvalue=1, offvalue=0,
                                 background=self.p)
        self.с_2_1.grid(row=5, column=0, padx=15, pady=10, columnspan=1, sticky=W)
        self.Check2 = BooleanVar()
        self.Check2.set(0)
        self.с_2_2 = Checkbutton(self.win3, text=self.g2[4], variable=self.Check2, onvalue=1, offvalue=0,
                                 background=self.g)
        self.с_2_2.grid(row=6, column=0, padx=15, pady=10, columnspan=1, sticky=W)
        self.Check3 = BooleanVar()
        self.Check3.set(0)
        self.с_2_3 = Checkbutton(self.win3, text=self.g2[5], variable=self.Check3, onvalue=1, offvalue=0,
                                 background=self.p)
        self.с_2_3.grid(row=7, column=0, padx=15, pady=10, columnspan=1, sticky=W)
        self.t_3 = Label(self.win3, text=self.a2[2], font=("Arial", 20), background=self.g)
        self.t_3.grid(row=8, column=1, columnspan=1, sticky=W)
        self.c_3_1 = Entry(self.win3, width=20, font=("Arial", 10))
        self.c_3_1.grid(row=9, column=0, sticky=W, padx=15, pady=10, )
        self.c_4 = Button(self.win3, width=20, text="Завершити", font=("Arial", 10), command=self.Ans_test1)
        self.c_4.grid(row=10, column=0, sticky=E, padx=15, pady=10, )
        if self.flag == 2:
            self.t_1_reas = Entry(self.win3, width=30, )
            self.t_1_reas.grid(row=0, column=2, sticky=W, padx=15, pady=10, )
            self.c_1_1_reas = Entry(self.win3, width=30, )
            self.c_1_1_reas.grid(row=1, column=1, sticky=W, padx=15, pady=10, )
            self.c_1_2_reas = Entry(self.win3, width=30, )
            self.c_1_2_reas.grid(row=2, column=1, sticky=W, padx=15, pady=10, )
            self.c_1_3_reas = Entry(self.win3, width=30, )
            self.c_1_3_reas.grid(row=3, column=1, sticky=W, padx=15, pady=10, )
            self.t_2_reas = Entry(self.win3, width=30, )
            self.t_2_reas.grid(row=4, column=2, sticky=W, padx=15, pady=10, )
            self.c_2_1_reas = Entry(self.win3, width=30, )
            self.c_2_1_reas.grid(row=5, column=1, sticky=W, padx=15, pady=10, )
            self.c_2_2_reas = Entry(self.win3, width=30, )
            self.c_2_2_reas.grid(row=6, column=1, sticky=W, padx=15, pady=10, )
            self.c_2_3_reas = Entry(self.win3, width=30, )
            self.c_2_3_reas.grid(row=7, column=1, sticky=W, padx=15, pady=10, )
            self.t_3_reas = Entry(self.win3, width=30, )
            self.t_3_reas.grid(row=8, column=2, sticky=W, padx=15, pady=10, )
            self.c_3_1_reas = Entry(self.win3, width=30, )
            self.c_3_1_reas.grid(row=9, column=1, sticky=W, padx=15, pady=10, )
            self.edit = Button(self.win3, width=20, text="Сохранить", font=("Arial", 10), command=self.Edit)
            self.edit.grid(row=10, column=2, sticky=E, padx=15, pady=10, )
         if self.flag == 1:
            self.aa = Label(self.win3, text="Твой ответ -{},а правильный трезубец".format(self.A), font=("Arial", 10),
                            background=self.g)
            self.aa.grid(row=12, column=0, columnspan=1, sticky=W)
            self.ab = Label(self.win3, text="Твоя оценка - {} из 3".format(self.podshet),
                            font=("Arial", 10), background=self.g)
            self.ab.grid(row=13, column=0, columnspan=1, sticky=W)
            self.podshet = 0
            self.p = "#808080"
            self.flag = 0
     def Reas(self):
        self.flag = 2
        self.win2.destroy()
        self.test1()
     def Edit(self):
        self.p="#808080"
        if self.t_1_reas .get()!="":
         self.a1[0]=self.t_1_reas .get()
        if self.t_2_reas.get() != "":
             self.a1[1] = self.t_2_reas.get()
        if self.t_3_reas.get() != "":
             self.a1[2] = self.t_3_reas.get()
        if self.c_1_1_reas.get() != "":
             self.g1[0] = self.c_1_1_reas.get()
        if self.c_1_2_reas.get() != "":
             self.g1[1] = self.c_1_2_reas.get()
        if self.c_1_3_reas.get() != "":
             self.g1[2] = self.c_1_3_reas.get()
        if self.c_2_1_reas.get() != "":
             self.g1[3] = self.c_2_1_reas.get()
        if self.c_2_2_reas.get() != "":
             self.g1[4] = self.c_2_2_reas.get()
        if self.c_2_3_reas.get() != "":
             self.g1[5] = self.c_2_3_reas.get()
        if self.c_3_1_reas.get() != "":
            self.a_3_1 = self.c_3_1_reas.get()
        self.flag="0"
        self.s = "0"
        self.win2.destroy()
        self.test1()
          def Ans_test1(self):
        self.A = self.c_3_1 .get()
        if self.Check1.get() == True:
            self.podshet =  self.podshet + 0.5
        if self.Check3.get() == True:
            self.podshet =  self.podshet + 0.5
        if self.Radio.get() == 1:
            self.podshet =  self.podshet + 1.0
        if self.A == self.a_3_1:
            self.podshet = self.podshet + 1.0
        self.p="#008000"
        self.flag=1
        if self.okno == 1:
            self.win2.destroy()
            self.test1()
        else:
            self.win3.destroy()
            self.test2()
     def Admin_on(self):
        self.s = self.Admin.get()
        if self.s == "1069":
            mb.showinfo("Адмін панель","Успешно")
            self.ad.destroy()
        else:
            mb.showerror("Адмін панель","Ошибка")
    def about(self):
        self.about = Toplevel(root)
        self.about.config(bd=20, bg='#ffaaaa')
        self.about.title("Інформація")
        self.about.resizable(False, False)
        Label(self.about, text="Мотрук Єгор", bg='#ffaaaa', font=("Arial 32", 20)).pack()
        Label(self.about, text="Группа ДА-82", bg='#ffaaaa', font=("Arial 32", 20)).pack()
     def admin(self):
        self.ad = Toplevel(root)
        self.ad.config(bd=20, bg='#ffaaaa')
        self.ad.title("Адмін панель")
        self.ad.resizable(False, False)
        Label1 = Label(self.ad, text="Ведіть пароль", bg='#ffaaaa', font=("Arial 32", 20))
        Label1.grid(row=0, column=0)
        self.Admin = Entry(self.ad, width=40, font=("Arial", 10))
        self.Admin.grid(row=1, column=0, sticky=W)
        AdminB= Button(self.ad, width=10, text="Ввести", font=("Arial", 10),command=self.Admin_on)
        AdminB.grid(row=15, column=0,pady=10, padx=10)
 root = Tk()
root.title("Головне меню")
start = Main()
root.mainloop()

[/apcode]

Надо разделить логику и отображение, и добавить классов, что бы, в том числе, реализовать полиморфизм и паттерны

Asked question
Добавить комментарий