Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- root = Tk()
- class MyCanvas:
- def __init__(self, parent):
- self.canvas1 = Canvas(parent, width=800, height = 300, bg='pink')
- self.canvas1.pack(side=BOTTOM)
- self.widgets()
- def widgets(self):
- #eq1
- self.eq1top = self.canvas1.create_text(55,20, text='Vav = Vi + Vf', font=('Times','12'),width=140)
- self.eq1line = self.canvas1.create_line(10,30, 105,30, fill='brown',width=1)
- self.eq1bottom = self.canvas1.create_text(65,40, text='2', font=('Times', '12'))
- #eq2
- self.eq2top = self.canvas1.create_text(75,65, text='Vi = ( Vav * 2 ) - Vf', font=('Times', '12'),width=140)
- #eq3
- self.eq3top = self.canvas1.create_text(75, 100, text='Vf = ( Vav * 2 ) - Vi', font=('Times', '12'),width=140)
- #eq4
- self.eq4top = self.canvas1.create_text(45,130, text='Vav = ▲d', font=('Times', '12'), width=140)
- self.eq4line = self.canvas1.create_line(55,140, 85,140, fill='brown', width=1)
- self.eq4bottom = self.canvas1.create_text(65,150, text='▲t', font=('Times', '12'))
- #eq5
- self.eq5top = self.canvas1.create_text(255,170, text=' '*20, font=('Times','12'))
- class MyApp:
- def __init__(self, parent):
- self.myLastbuttoninvoked = None
- self.myContainer1 = Frame(parent)
- self.myContainer1.pack()
- self.button1 = Button(self.myContainer1)
- self.button1.configure(text='ColorChanger', background='green', command=self.button1Click)
- self.button1.configure(width=15, border=10)
- self.button1.pack(side=LEFT)
- self.button1.focus_force()
- self.button2 = Button(self.myContainer1, command=self.button2Click)
- self.button2.configure(text='ButtonChanger', background='white',width=15)
- self.button2.configure(border=10)
- self.button2.pack(side=LEFT, padx=20, pady=20)
- self.button3 = Button(self.myContainer1, command=self.start_canvas)
- self.button3.configure(text='Formulae',width=15, border=10, background='wheat')
- self.button3.pack(side=LEFT)
- self.button4 = Button(self.myContainer1, command=self.loop_text)
- self.button4.configure(text='Questions', width=15, border=10, background='yellowgreen')
- self.button4.pack(side=LEFT, padx=20, pady=20)
- self.label = Label(parent, text='Empty', bg='black', fg='brown', font=('Helvetica','12'))
- #self.label.pack(side=BOTTOM)
- def button1Click(self):
- self.myLastbuttoninvoked = 'Color Changer'
- print ('Color Change Clicked')
- if self.button1['background'] == 'green':
- self.button1['background'] = 'yellow'
- print ('color showing is YELLOW')
- elif self.button1['background'] == 'yellow':
- self.button1['background'] = 'orange'
- print ('color showing is ORANGE')
- else:
- self.button1['background'] = 'green'
- print ('color showing is GREEN')
- def button2Click(self):
- self.myLastbuttoninvoked = 'Button Changer'
- print ('Button Change Clicked')
- if self.button2['relief'] == 'ridge':
- self.button2['relief'] = 'groove'
- print ('Current button is GROOVE')
- elif self.button2['relief'] == 'groove':
- self.button2['relief'] = 'flat'
- print ('Current button is FLAT')
- else:
- self.button2['relief'] = 'ridge'
- print ('Current button is RIDGE')
- def start_canvas(self):
- print ('Canvas Formulae is on display')
- mycanvas = MyCanvas(root)
- self.button3.configure(state='disable')
- def start_label(self):
- mylabel = MyQuestions(root)
- def loop_text(self):
- print ('Label of text has began')
- #self.button4.configure(state='disable')
- self.question1 = '1111 represents question 1, other thing will be happening and nothing will show, \n I would like to see what it shows when I have a long text'
- self.question2 = '2222 represents question 2, other thing will be happening and nothing will show, \n I would like to see what it shows when I have a long text'
- self.question3 = '3333 represents question 3, other thing will be happening and nothing will show, \n I would like to see what it shows when I have a long text'
- self.question4 = '4444 represents question 4, other thing will be happening and nothing will show, \n I would like to see what it shows when I have a long text'
- self.label.pack(side=BOTTOM)
- if self.label['text'] == self.question1:
- self.label['text'] = self.question2
- print ('Currently displaying Text 2')
- elif self.label['text'] == self.question2:
- self.label['text'] = self.question3
- print ('Currently displaying Text 3')
- elif self.label['text'] == self.question3:
- self.label['text'] = self.question4
- print ('Currently displaying Text 4')
- else:
- self.label['text'] = self.question1
- print ('Currently displaying text 1')
- print ("\n"*100) # a simple way to clear the screen
- print ("starting........")
- root.title('Having some Fun ')
- myapp = MyApp(root)
- root.mainloop()
- print ("........ Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement