Lab 3

  1. Create a working directory lab3 and download the source files from Canvas tutorial folder. Import all files into Eclipse. Dissect and test run all programs.

  2. Find the algorithm to solve this SliderPuzzle Game
  3. Given the program slider.py in tutorial folder, modify the code to add two buttons; one to reset puzzle to its initial position, and one to randomize the puzzle.

  4. Create a python program which lays out a simple mobile phone and display the button press i.e. button label on the text area. Your mobile phone will have the following components:

    Use any mobile phone for a sample layout. The layout manager is your choice as is the use of labels, colors, and button name.

  5. Given the guiNotep25.py programe to solve a quadratic equation.
    
    import sys
    import math
    import tkinter as tk
    
    class Gui:
        def __init__(self, root):
            self.root = root
            self.root.geometry('300x400')
            
            self.label1 = tk.Label(self.root,text = 'a :')
            self.label1.place(x=5,y=5)
            self.entry1 = tk.Entry(self.root,width= 25)
            self.entry1.place(x=25, y=5)
    
            self.label2 = tk.Label(self.root,text = 'b :')
            self.label2.place(x = 5,y = 55)
            self.entry2 = tk.Entry(self.root,width= 25)
            self.entry2.place(x = 25, y = 55)
            
            self.label3 = tk.Label(self.root,text = 'c :')
            self.label3.place(x = 5, y = 105)
            self.entry3 = tk.Entry(self.root,width= 25)
            self.entry3.place(x = 25, y = 105)
            
            self.btn1 = tk.Button(self.root, text='Calculate', \
                                  command=self.calulateRoot)
            self.btn1.place(x=5,y=155)
            
            self.text1 = tk.Text(self.root,width= 20, height=5)
            self.text1.place(x=25, y=200)
                    
        def calulateRoot(self):
            
            a = int(self.entry1.get())
            b = int(self.entry2.get())
            c = int(self.entry3.get())
            
            x1=(-b+math.sqrt(b*b-4*a*c))/2*a
            x2=(-b-math.sqrt(b*b-4*a*c))/2*a      
     
            self.text1.insert(tk.END,'x1 = '+str(x1)+'\n'+'x2 = '+str(x2))
            
    def main():
        root = tk.Tk()
        Gui(root)
        root.mainloop()
    
    if __name__ == '__main__':
        sys.exit(main())
    

    Rewrite the above program to add a Quit button to exit the program using the QuitButton class in Week1 tutorial folder and exception handling using another Text component for the display of error messages.

    Draw the class diagram of your program completed.

  6. Write GUI version of the loantable application as belows.

    Example of normal test case:

    Example of invalid case:

    Draw the class diagram of your program completed.