1

I want to make a program that draws a diagram of Lennard-Jones potential with parameters epsilon and sigma being adjustable with two sliders. I want my program to work like this

  1. Small window with two sliders appear
  2. I adjust both sliders
  3. I click "show"
  4. A diagram of potential appears

This is my code:

from Tkinter import *

import pylab as p

def show_values():
    V=4*epsilon.get()*(math.pow((sigma.get()/r),12)-math.pow((sigma.get()/r,6)))
    p.plot(t,V)
    p.show()


r = p.arange(0.1, 5.0, 0.01)
master = Tk()
epsilon = Scale(master, from_=0, to=42)
epsilon.pack()
sigma = Scale(master, from_=0, to=200, orient=HORIZONTAL)
sigma.pack()



Button(master, text='Show', command=show_values).pack()
master.mainloop()

When I click "run the current file" nothing happens. No error messages. Whad I did wrong? I work in canopy 32-bit, windows 7.

user46147
  • 232
  • 1
  • 16

1 Answers1

1

Once you have constructed your window, you need to call the mainloop() method to show it. Adding master.mainloop() after the last line does the trick.

dncook
  • 306
  • 2
  • 10
  • I added master.mainloop() after the last line and still nothing happens. I edited my question, so the code includes your suggestion. :-) – user46147 Nov 01 '14 at 22:26
  • Oh! Excuse me! It's just my laptop working slowly. Something happened: window with sliders appeared. But now, when I click "show"... nothing happens. – user46147 Nov 01 '14 at 22:42
  • O.... and now I noticed some errors in the rest of the code: p.plot(t,V) should be replaced with p.plot(r,V). And there were some problems with math.pow, so I replaced it with ** – user46147 Nov 01 '14 at 23:02