Exemple #1
0
    def create_frames(self):
        self.pf = Frame(self.parent)
        self.pf.configure(bg=GrayScale(0))
        self.pf.place(relx=self.relx,
                      rely=self.rely,
                      relwidth=self.relwidth,
                      relheight=self.relheight)

        self.f1 = MyFrame(self.pf, GrayScale(80))
        self.f2 = MyFrame(self.pf, GrayScale(60))
        self.f3 = MyFrame(self.pf, GrayScale(40))

        self.b1 = MyButton(self.f1, self.o_list[0], self.func1, 0, 0)
        self.b2 = MyButton(self.f2, self.o_list[1], self.func2, 0, 0)
        self.b3 = MyButton(self.f3, self.o_list[2], self.func3, 0, 0)

        self.b1.configure(bg=GrayScale(80), activebackground=GrayScale(80))
        self.b2.configure(bg=GrayScale(60), activebackground=GrayScale(60))
        self.b3.configure(bg=GrayScale(40), activebackground=GrayScale(40))

        self.b1.place(relwidth=1, relheight=1)
        self.b2.place(relwidth=1, relheight=1)
        self.b3.place(relwidth=1, relheight=1)

        self.f1.tkraise()
Exemple #2
0
    def __init__(self, parent, question_text, ans1_text, ans2_text, ans3_text,
                 ans4_text, exp1_text, exp2_text, exp3_text, exp4_text,
                 correct_ans):
        # assigning parameters to attributes
        self.parent = parent
        self.qtext = str(question_text)
        self.text1 = str(ans1_text)
        self.text2 = str(ans2_text)
        self.text3 = str(ans3_text)
        self.text4 = str(ans4_text)
        self.exp1 = str(exp1_text)
        self.exp2 = str(exp2_text)
        self.exp3 = str(exp3_text)
        self.exp4 = str(exp4_text)
        self.ans = int(correct_ans)

        # creating Tkinter variables
        self.ans_input = IntVar()
        self.is_correct = BooleanVar()
        self.efbg = StringVar()
        self.is_correct_text = StringVar()
        self.exp_text = StringVar()

        # developer mode
        if dev:
            self.ans_input.set(self.ans)

        # questionwide bgcolor, fgcolor
        self.bgcolor = GrayScale(80)
        self.fgcolor = GrayScale(20)

        # creating parent frame
        self.parent_frame()
        self.question_frame()
Exemple #3
0
class MyEntry(Entry):
    charwidth = 20
    bgcolor = GrayScale(20)
    fgcolor = GrayScale(220)

    def __init__(self, parent, text, relx, rely):
        self.parent = parent
        self.text = text
        self.relx = relx
        self.rely = rely

        Entry.__init__(self, self.parent)

        self.entry_configure_()
        self.entry_place_()

        self.label_rely = self.rely - 0.050
        self.label_create_()

    def entry_configure_(self):
        self.configure(width=self.charwidth, font=MyFonts['Default'])
        self.configure(bg=self.bgcolor, fg=self.fgcolor)
        self.configure(relief=RIDGE, highlightthickness=2, bd=0)

    def entry_place_(self):
        self.place(relx=self.relx, rely=self.rely)

    def label_create_(self):
        self.label = MyLabel(self.parent, self.text, self.relx,
                             self.label_rely)
        self.label.configure(font=MyFonts['Large'])
Exemple #4
0
    def create_frame3c(self):
        self.frame3c_entry1 = MyOutputEntry(self.frame3c,
                                            'Moment of Inertia (kgm²)', 0.20,
                                            0.25)
        self.frame3c_entry2 = MyOutputEntry(self.frame3c,
                                            'Rotational Kinetic Energy (J)',
                                            0.20, 0.40)
        self.frame3c_entry3 = MyOutputEntry(self.frame3c,
                                            'Linear Kinetic Energy (J)', 0.20,
                                            0.55)
        self.frame3c_entry4 = MyOutputEntry(self.frame3c,
                                            'Total Kinetic Energy (J)', 0.20,
                                            0.70)

        self.calculate_button_3c = MyImageButton(
            self.frame3c, GrayScale(20),
            CreateTkImage('data/images/calculator.png', 48, 48),
            self.calculate_3c, 0.75, 0.25)
        self.calculate_button_3c.configure(bg=GrayScale(20),
                                           activebackground=GrayScale(20))
        self.calculate_button_3c.place(relwidth=0.10, relheight=0.10)

        if tooltips:
            CreateToolTip(self.frame3c_entry1.label, 'I = ½ MR²')
            CreateToolTip(self.frame3c_entry2.label, 'RKE = ½ Iw²')
            CreateToolTip(self.frame3c_entry3.label, 'LKE = ½ MV²')
            CreateToolTip(self.frame3c_entry4.label, 'TKE = RKE + LKE')
Exemple #5
0
class MyButton(Button):
    bgcolor = GrayScale(40)
    fgcolor = GrayScale(220)

    # default active colors are the same as idle colors
    abgcolor = bgcolor
    afgcolor = fgcolor

    relwidth = 0.10
    relheight = 0.05

    def __init__(self, parent, text, command, relx, rely):
        self.text = text
        self.command = command
        self.relx = relx
        self.rely = rely

        Button.__init__(self, parent)

        self.configure_()
        self.place_()

    def configure_(self):
        self.configure(text=self.text, command=self.command)
        self.configure(font=MyFonts['DefaultBold'])
        self.configure(bg=self.bgcolor, fg=self.fgcolor)
        self.configure(activebackground=self.abgcolor,
                       activeforeground=self.afgcolor)
        self.configure(relief=RIDGE, highlightthickness=0, bd=0)

    def place_(self):
        self.place(relx=self.relx,
                   rely=self.rely,
                   relwidth=self.relwidth,
                   relheight=self.relheight)
Exemple #6
0
    def create_frame3a(self):
        self.frame3a_entry1 = MyOutputEntry(self.frame3a,
                                            'Moment of Inertia (kgm²)', 0.20,
                                            0.25)

        self.calculate_button_3a = MyImageButton(
            self.frame3a, GrayScale(20),
            CreateTkImage('data/images/calculator.png', 48, 48),
            self.calculate_3a, 0.75, 0.25)
        self.calculate_button_3a.configure(bg=GrayScale(20),
                                           activebackground=GrayScale(20))
        self.calculate_button_3a.place(relwidth=0.10, relheight=0.10)

        if tooltips:
            CreateToolTip(self.frame3a_entry1.label, 'I = ½ MR²')
    def __init__(self, root):
        self.parent = root

        self.main_bf = MyFrame(self.parent, GrayScale(20))
        self.create_objects()

        self.setAll()
Exemple #8
0
 def showtip(self, text):
     self.text = text
     if self.tipwindow or not self.text:
         return
     x, y, cx, cy = self.widget.bbox('insert')
     x = x + self.widget.winfo_rootx() + 60
     y = y + cy + self.widget.winfo_rooty() + 30
     self.tipwindow = tw = Toplevel(self.widget)
     tw.wm_overrideredirect(1)
     tw.wm_geometry('+%d+%d' % (x, y))
     label = Label(tw, text=self.text)
     label.configure(justify=LEFT)
     label.configure(relief=SOLID, bd=1)
     label.configure(bg=GrayScale(60),
                     fg=GrayScale(220),
                     font=MyFonts['Default'])
     label.pack(ipadx=1)
Exemple #9
0
 def exp_label(self):
     # creating exp_label for explanation frame
     self.el = Label(self.ef)
     self.el.configure(text=self.exp_text.get())
     self.el.configure(font=MyFonts['LargeBold'])
     self.el.configure(bg=self.efbg.get(), fg=GrayScale(20))
     self.el.configure(relief=FLAT)
     self.el.configure(padx=2, pady=2, anchor=N)
     self.el.place(relx=0.05, rely=0.10, relwidth=0.90, relheight=0.85)
Exemple #10
0
    def create_frame2b(self):
        self.frame2b_entry1 = MyOutputEntry(self.frame2b,
                                            'Moment of Inertia (kgm²)', 0.20,
                                            0.25)
        self.frame2b_entry2 = MyOutputEntry(self.frame2b,
                                            'Angular Momentum (kgm²/s)', 0.20,
                                            0.40)

        self.calculate_button_2b = MyImageButton(
            self.frame2b, GrayScale(20),
            CreateTkImage('data/images/calculator.png', 48, 48),
            self.calculate_2b, 0.75, 0.25)
        self.calculate_button_2b.configure(bg=GrayScale(20),
                                           activebackground=GrayScale(20))
        self.calculate_button_2b.place(relwidth=0.10, relheight=0.10)

        if tooltips:
            CreateToolTip(self.frame2b_entry1.label, 'I = ½ MR²')
            CreateToolTip(self.frame2b_entry2.label, 'L = Iw')
Exemple #11
0
    def __init__(self, parent, path, x_size, y_size):
        if dev:
            print '[image] image created from ' + path
        self.img_frame = MyFrame(parent, GrayScale(20))

        img_object = CreateTkImage(path, x_size, y_size)

        self.img_label = Label(self.img_frame, image=img_object)
        self.img_label.image = img_object
        self.img_label.place(relx=0, rely=0, relwidth=1, relheight=1)
Exemple #12
0
    def create_nav(self):
        if dev:
            print '[main] navigation buttons created'

        self.enter_as = MyImageButton(
            self.main_pf1, GrayScale(20),
            CreateTkImage('data/images/settings.png', 32, 32),
            self.flip_main_pf2, 0.05, fb_rely_primary)

        self.exit_as = MyImageButton(
            self.main_pf2, GrayScale(20),
            CreateTkImage('data/images/back.png', 32, 32), self.flip_main_pf1,
            0.175, 0.85)

        self.exit_as.place(relwidth=0.125, relheight=0.0625)

        self.frame_cycle = MyCycleButton3(
            self.main_pf1,
            ['Orbiting Particle', 'Rotating Circle', 'Rolling Circle'],
            [self.scales, self.frame1, self.frame2, self.frame3], 0.85,
            fb_rely_primary)
    def create_objects(self):
        self.title_label = MyLabel(self.main_bf, 'Modify Program Settings',
                                   0.05, 0.05)
        self.title_label.configure(font=MyFonts['ExtraLargeBold'])
        self.title_label.place(relwidth=0.9)

        self.width_entry = MyEntry(self.main_bf, 'Window Width (pixels)', 0.25,
                                   0.20)
        self.width_entry.label.place(relwidth=0.90, relx=0.05)
        self.width_entry.place(relwidth=0.50)

        self.height_entry = MyEntry(self.main_bf, 'Window Height (pixels)',
                                    0.25, 0.35)
        self.height_entry.label.place(relwidth=0.90, relx=0.05)
        self.height_entry.place(relwidth=0.50)

        self.font_entry = MyEntry(self.main_bf, 'Font Name', 0.25, 0.50)
        self.font_entry.label.place(relwidth=0.90, relx=0.05)
        self.font_entry.place(relwidth=0.50)

        self.font_size_entry = MyEntry(self.main_bf, 'Font Size (points)',
                                       0.25, 0.65)
        self.font_size_entry.label.place(relwidth=0.90, relx=0.05)
        self.font_size_entry.place(relwidth=0.50)

        self.tooltips_button = MyToggleButton(self.main_bf, 'Tooltips', 0.15,
                                              0.80)

        self.reset_button = MyImageButton(
            self.main_bf, GrayScale(20),
            CreateTkImage('data/images/reset.png', 48, 48), self.funcReset,
            0.45, 0.82)
        self.reset_button.place(relwidth=0.14, relheight=0.07)

        self.save_button = MyImageButton(
            self.main_bf, GrayScale(20),
            CreateTkImage('data/images/save.png', 48, 48), self.funcSave, 0.70,
            0.82)
        self.save_button.place(relwidth=0.14, relheight=0.07)
Exemple #14
0
    def calc_score(self):
        if not self.score_calculated:
            if dev:
                print '[game] calculating final score'

            # figuring out how many questions were correct:
            tmp_var = 0
            for question in self.qlist:
                if question.is_correct.get():
                    tmp_var += 1

            self.score_label = MyLabel(
                self.end_frame, 'You got ' + str(tmp_var) + '/' +
                str(len(self.qlist)) + ' questions correct!', 0.25, 0.55)
            self.score_label.configure(font=MyFonts['LargeBold'],
                                       bg=GrayScale(80),
                                       fg=GrayScale(220))
            self.score_label.place(relwidth=0.50, relheight=0.15)

            self.score_calculated = True
        else:
            return
Exemple #15
0
    def create_end_frame(self):
        if dev:
            print '[game] end frame created'

        self.end_frame = MyFrame(self.game_bf, GrayScale(80))

        self.end_label = MyLabel(self.end_frame,
                                 'You have finished the Quiz Game!', 0.25,
                                 0.25)
        self.end_label.configure(font=MyFonts['ExtraLarge'],
                                 bg=GrayScale(80),
                                 fg=GrayScale(220))
        self.end_label.place(relwidth=0.50, relheight=0.15)

        self.score_button = MyButton(self.end_frame, 'Calculate Score',
                                     self.calc_score, 0.45, 0.45)

        self.credits_label = MyLabel(self.end_frame, 'Questions by:'
                                     '\nLian Chao Hooi', 0.25, 0.85)

        self.credits_label.configure(bg=GrayScale(80),
                                     anchor=N,
                                     font=MyFonts['Default'])
        self.credits_label.place(relwidth=0.50)
Exemple #16
0
class MyLabel(Label):
    bgcolor = GrayScale(20)
    fgcolor = GrayScale(220)

    def __init__(self, parent, text, relx, rely):
        self.parent = parent
        self.text = text
        self.relx = relx
        self.rely = rely

        Label.__init__(self, self.parent)

        self.configure_()
        self.place_()

    def configure_(self):
        self.configure(text=self.text)
        self.configure(font=MyFonts['Default'])
        self.configure(bg=self.bgcolor, fg=self.fgcolor)
        self.configure(relief=FLAT, anchor=N)
        self.configure(padx=2, pady=2)

    def place_(self):
        self.place(relx=self.relx, rely=self.rely)
Exemple #17
0
    def create_frames(self):
        self.pf = Frame(self.parent)
        self.pf.configure(bg=GrayScale(0))
        self.pf.place(relx=self.relx,
                      rely=self.rely,
                      relwidth=self.relwidth,
                      relheight=self.relheight)

        self.f1 = MyFrame(self.pf, GrayScale(80))
        self.f2 = MyFrame(self.pf, GrayScale(60))

        self.b1 = MyButton(self.f1, 'Disabled', self.func1, 0, 0)
        self.b2 = MyButton(self.f2, 'Enabled', self.func2, 0, 0)

        self.b1.configure(bg=GrayScale(40), activebackground=GrayScale(180))
        self.b2.configure(bg=GrayScale(180),
                          activebackground=GrayScale(40),
                          fg=GrayScale(20))

        self.b1.place(relwidth=1, relheight=1)
        self.b2.place(relwidth=1, relheight=1)
Exemple #18
0
    def create_game_bf(self):
        if dev:
            print '[game] game base frame created'

        self.game_bf = MyFrame(self.parent, GrayScale(20))
Exemple #19
0
    def create_animation_frame(self):
        if dev:
            print '[main] animation frame objects created'

        self.main_pf2_title = MyLabel(self.main_pf2, 'Animation Settings',
                                      0.175, 0.125)
        self.main_pf2_title.configure(bg=GrayScale(20),
                                      font=MyFonts['LargeBold'])
        self.main_pf2_title.place(relwidth=0.65)

        self.time_factor_scale = MyScale(self.main_pf2, 'Time Factor', 0.175,
                                         0.25)
        self.len_mult_scale = MyScale(self.main_pf2, 'Length Multiplier',
                                      0.175, 0.40)
        self.granularity_scale = MyScale(self.main_pf2, 'Granularity', 0.175,
                                         0.55)

        self.time_factor_scale.configure(from_=1,
                                         to=100,
                                         resolution=1,
                                         bg=GrayScale(20))
        self.len_mult_scale.configure(from_=1,
                                      to=100,
                                      resolution=1,
                                      bg=GrayScale(20))
        self.granularity_scale.configure(from_=5,
                                         to=90,
                                         resolution=5,
                                         bg=GrayScale(20))

        self.time_factor_scale.label.configure(bg=GrayScale(20),
                                               font=MyFonts['Large'])
        self.len_mult_scale.label.configure(bg=GrayScale(20),
                                            font=MyFonts['Large'])
        self.granularity_scale.label.configure(bg=GrayScale(20),
                                               font=MyFonts['Large'])

        self.time_factor_scale.place(relwidth=0.65)
        self.len_mult_scale.place(relwidth=0.65)
        self.granularity_scale.place(relwidth=0.65)

        self.time_factor_scale.label.place(relwidth=0.65)
        self.len_mult_scale.label.place(relwidth=0.65)
        self.granularity_scale.label.place(relwidth=0.65)

        if dev:
            self.time_factor_scale.set(1)
            self.len_mult_scale.set(100)
            self.granularity_scale.set(5)

        if not dev:
            self.time_factor_scale.set(5)
            self.len_mult_scale.set(5)
            self.granularity_scale.set(5)

        if tooltips:
            CreateToolTip(
                self.time_factor_scale.label,
                'Drag slider to adjust animation speed.'
                '\nHigher value is faster.')

            CreateToolTip(
                self.len_mult_scale.label,
                'Drag slider to adjust animation scale.'
                '\nHigher value is bigger.')

            CreateToolTip(
                self.granularity_scale.label,
                'Drag slider to adjust animation smoothness'
                '\nHigher value is smoother')
Exemple #20
0
    def create_frames(self):
        if dev:
            print '[main] frames created'

        self.main_bf = MyFrame(self.parent, GrayScale(20))
        self.main_pf1 = MyFrame(self.main_bf, GrayScale(20))
        self.main_pf2 = MyFrame(self.main_bf, GrayScale(20))
        self.scales = MyInputFrame(self.main_pf1, GrayScale(20))
        self.frame1 = MyFrameWBP1(self.main_pf1, GrayScale(20))
        self.frame2 = MyFrameWBP1(self.main_pf1, GrayScale(20))
        self.frame3 = MyFrameWBP1(self.main_pf1, GrayScale(20))
        self.frame1a = MyOutputFrame(self.frame1, GrayScale(20))
        self.frame1b = MyOutputFrame(self.frame1, GrayScale(20))
        self.frame1c = MyOutputFrame(self.frame1, GrayScale(20))
        self.frame2a = MyOutputFrame(self.frame2, GrayScale(20))
        self.frame2b = MyOutputFrame(self.frame2, GrayScale(20))
        self.frame2c = MyOutputFrame(self.frame2, GrayScale(20))
        self.frame3a = MyOutputFrame(self.frame3, GrayScale(20))
        self.frame3b = MyOutputFrame(self.frame3, GrayScale(20))
        self.frame3c = MyOutputFrame(self.frame3, GrayScale(20))
Exemple #21
0
class MyScale(Scale):
    bgcolor = GrayScale(20)
    fgcolor = GrayScale(220)

    lowrange = 1.0
    highrange = 100.0
    resolution = 0.1

    s_relwidth = scale_relwidth
    s_relheight = scale_relheight

    def __init__(self, parent, text, relx, rely):
        # making parameters into attributes
        self.parent = parent
        self.text = text
        self.relx = relx
        self.rely = rely

        # creating Tkinter variables
        self.l_val = StringVar()

        Scale.__init__(self, self.parent)

        self.scale_configure_()
        self.scale_place_()
        self.label_create_()

    def scale_configure_(self):
        self.configure(command=self.update)
        self.configure(from_=self.lowrange, to=self.highrange)
        self.configure(orient=HORIZONTAL,
                       showvalue=0,
                       resolution=self.resolution)
        self.configure(bg=self.bgcolor, fg=self.fgcolor)
        self.configure(relief=RIDGE, highlightthickness=0, bd=0)

    def scale_place_(self):
        self.place(relx=self.relx,
                   rely=(self.rely + 0.01),
                   relwidth=self.s_relwidth,
                   relheight=self.s_relheight)

    def label_create_(self):
        self.label = Label(self.parent)

        self.label_configure_()
        self.label_place_()

    def label_configure_(self):
        self.label.configure(textvariable=self.l_val)
        self.label.configure(font=MyFonts['Large'])
        self.label.configure(bg=self.bgcolor, fg=self.fgcolor)
        self.label.configure(relief=FLAT)
        self.label.configure(padx=2, pady=2)

    def label_place_(self):
        label_rely = self.rely - 0.050
        self.label.place(relx=self.relx, rely=label_rely)

    def update(self, *args):
        self.l_val.set(self.text + ' = ' + str(Scale.get(self)))
Exemple #22
0
 def configure_(self):
     self.configure(bg=GrayScale(20))
     self.configure(width=canvas_width, height=canvas_height)
     self.configure(relief=RIDGE, bd=2)