Advertisement
Guest User

troubled code

a guest
Jan 16th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.29 KB | None | 0 0
  1. from tkinter import *
  2. root = Tk()
  3.  
  4. class MyCanvas:
  5.     def __init__(self, parent):
  6.         self.canvas1 = Canvas(parent, width=800, height = 300, bg='pink')
  7.         self.canvas1.pack(side=BOTTOM)
  8.         self.widgets()
  9.  
  10.     def widgets(self):
  11.         #eq1
  12.         self.eq1top = self.canvas1.create_text(55,20, text='Vav = Vi + Vf', font=('Times','12'),width=140)
  13.         self.eq1line = self.canvas1.create_line(10,30, 105,30, fill='brown',width=1)
  14.         self.eq1bottom = self.canvas1.create_text(65,40, text='2', font=('Times', '12'))
  15.  
  16.         #eq2
  17.         self.eq2top = self.canvas1.create_text(75,65, text='Vi = ( Vav * 2 ) - Vf', font=('Times', '12'),width=140)
  18.  
  19.         #eq3
  20.         self.eq3top = self.canvas1.create_text(75, 100, text='Vf = ( Vav * 2 ) - Vi', font=('Times', '12'),width=140)
  21.  
  22.         #eq4
  23.         self.eq4top = self.canvas1.create_text(45,130, text='Vav = ▲d', font=('Times', '12'), width=140)
  24.         self.eq4line = self.canvas1.create_line(55,140, 85,140, fill='brown', width=1)
  25.         self.eq4bottom = self.canvas1.create_text(65,150, text='▲t', font=('Times', '12'))
  26.  
  27.         #eq5
  28.         self.eq5top = self.canvas1.create_text(255,170, text=' '*20, font=('Times','12'))
  29.  
  30.  
  31. class MyApp:
  32.     def __init__(self, parent):
  33.         self.myLastbuttoninvoked = None
  34.  
  35.         self.myContainer1 = Frame(parent)
  36.         self.myContainer1.pack()
  37.  
  38.         self.button1 = Button(self.myContainer1)
  39.         self.button1.configure(text='ColorChanger', background='green', command=self.button1Click)
  40.         self.button1.configure(width=15, border=10)
  41.         self.button1.pack(side=LEFT)
  42.         self.button1.focus_force()
  43.  
  44.         self.button2 = Button(self.myContainer1, command=self.button2Click)
  45.         self.button2.configure(text='ButtonChanger', background='white',width=15)
  46.         self.button2.configure(border=10)
  47.         self.button2.pack(side=LEFT, padx=20, pady=20)
  48.        
  49.  
  50.         self.button3 = Button(self.myContainer1, command=self.start_canvas)
  51.         self.button3.configure(text='Formulae',width=15, border=10, background='wheat')
  52.         self.button3.pack(side=LEFT)
  53.  
  54.         self.button4 = Button(self.myContainer1, command=self.loop_text)
  55.         self.button4.configure(text='Questions', width=15, border=10, background='yellowgreen')
  56.         self.button4.pack(side=LEFT, padx=20, pady=20)
  57.  
  58.         self.label = Label(parent, text='Empty', bg='black', fg='brown', font=('Helvetica','12'))
  59.         #self.label.pack(side=BOTTOM)
  60.  
  61.     def button1Click(self):
  62.         self.myLastbuttoninvoked = 'Color Changer'
  63.         print ('Color Change Clicked')
  64.         if self.button1['background'] == 'green':
  65.             self.button1['background'] = 'yellow'
  66.             print ('color showing is YELLOW')
  67.         elif self.button1['background'] == 'yellow':
  68.             self.button1['background'] = 'orange'
  69.             print ('color showing is ORANGE')
  70.         else:
  71.             self.button1['background'] = 'green'
  72.             print ('color showing is GREEN')
  73.                
  74.     def button2Click(self):
  75.         self.myLastbuttoninvoked = 'Button Changer'
  76.         print ('Button Change Clicked')
  77.         if self.button2['relief'] == 'ridge':
  78.             self.button2['relief'] = 'groove'
  79.             print ('Current button is GROOVE')
  80.         elif self.button2['relief'] == 'groove':
  81.             self.button2['relief'] = 'flat'
  82.             print ('Current button is FLAT')
  83.         else:
  84.             self.button2['relief'] = 'ridge'
  85.             print ('Current button is RIDGE')
  86.  
  87.     def start_canvas(self):
  88.         print ('Canvas Formulae is on display')
  89.         mycanvas = MyCanvas(root)
  90.         self.button3.configure(state='disable')
  91.  
  92.     def start_label(self):
  93.         mylabel = MyQuestions(root)
  94.  
  95.  
  96.     def loop_text(self):
  97.         print ('Label of text has began')
  98.         #self.button4.configure(state='disable')
  99.         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'
  100.         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'
  101.         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'
  102.         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'
  103.         self.label.pack(side=BOTTOM)
  104.  
  105.         if self.label['text'] == self.question1:
  106.             self.label['text'] = self.question2
  107.             print ('Currently displaying Text 2')
  108.         elif self.label['text'] == self.question2:
  109.             self.label['text'] = self.question3
  110.             print ('Currently displaying Text 3')
  111.         elif self.label['text'] == self.question3:
  112.             self.label['text'] = self.question4
  113.             print ('Currently displaying Text 4')
  114.         else:
  115.             self.label['text'] = self.question1
  116.             print ('Currently displaying text 1')  
  117.  
  118. print ("\n"*100) # a simple way to clear the screen
  119. print ("starting........")
  120. root.title('Having some Fun ')
  121. myapp = MyApp(root)
  122. root.mainloop()
  123. print ("........ Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement