Monday, 2 September 2013

Update Tkinter Label

Update Tkinter Label

I use Python 3 and I'm quite new to programming. I have written a code
that's supposed to show a window in which you can move around two planets
and see the gravitational force between them. Everything works excepted
the label that's supposed to display the force. After multiple attempts
and searches, I just can't find out how to update it every time a planet
is being moved.
I guess my problem should be in the last line with :
lbl = Label(wind, bg = 'white', text = gravitation(oval1,
oval2)).pack(padx=5, pady=5)
I've tried to use a StringVar and a textvariable parameter but I didn't
really get the concepts of it.
Here is my code. I guess the answer is easy but I'm quite unexperienced.
from tkinter import *
import math
x, y = 135, 135
gravitation = 0
def gravitation (obj1,obj2):
a, b, c, d = can.coords (obj1)
e, f, g, h = can.coords (obj2)
dist = math.sqrt ((((a+c)/2)-((e+g)/2))**2+(((b+d)/2)-((f+h)/2))**2)
grav = 6.67384/dist
return grav
def move (ov, lr, tb): # function to move the ball
coo = can.coords(ov)
coo[0] = coo[0] + lr
coo[1] = coo[1] + tb
coo[2] = coo[0]+30
coo[3] = coo[1]+30
can.coords(ov, *coo)
def moveLeft ():
move(oval1, -10, 0)
def moveRight ():
move(oval1, 10, 0)
def moveTop ():
move(oval1, 0, -10)
def moveBottom ():
move(oval1, 0, 10)
def moveLeft2 ():
move(oval2, -10, 0)
def moveRight2 ():
move(oval2, 10, 0)
def moveTop2 ():
move(oval2, 0, -10)
def moveBottom2 ():
move(oval2, 0, 10)
##########MAIN############
wind = Tk() # Window and canvas
wind.title ("Move Da Ball")
can = Canvas (wind, width = 300, height = 300, bg = "light blue")
can.pack (side = LEFT,padx = 5, pady = 5)
Button(wind, text = 'Quit', command=wind.destroy).pack(padx = 5, pady = 5)
oval1 = can.create_oval(x,y,x+30,y+30,width=2,fill='orange') #Planet 1
moving etc
Button(wind, text = 'Left', command=moveLeft).pack(padx = 5, pady = 5)
Button(wind, text = 'Right', command=moveRight).pack(padx = 5, pady = 5)
Button(wind, text = 'Top', command=moveTop).pack(padx = 5, pady = 5)
Button(wind, text = 'Bottom', command=moveBottom).pack(padx = 5, pady = 5)
oval2 = can.create_oval(x+50,y+50,x+80,y+80,width=2,fill='orange') #Planet
2 moving etc
Button(wind, text = 'Left', command=moveLeft2).pack(padx = 5, pady = 5)
Button(wind, text = 'Right', command=moveRight2).pack(padx = 5, pady = 5)
Button(wind, text = 'Top', command=moveTop2).pack(padx = 5, pady = 5)
Button(wind, text = 'Bottom', command=moveBottom2).pack(padx = 5, pady = 5)
lbl = Label(wind, bg = 'white', text = gravitation(oval1,
oval2)).pack(padx=5, pady=5)
wind.mainloop()

How create a battery level array?

How create a battery level array?

I need to create a battery level array to insert it in a graph like
values.add( batterylevel )
How can i create this array? I mean, i know how create an array but i
don't know how create one for the battery level. How can i do it? This is
a way to have the battery level
public float getBatteryLevel() {
Intent batteryIntent = registerReceiver(null, new
IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
// Error checking that probably isn't needed but I added just in case.
if(level == -1 || scale == -1) {
return 50.0f;
}
return ((float)level / (float)scale) * 100.0f;
}
I need have double value to intert it in the chart.

solr delta import handler timestamp not specific enough

solr delta import handler timestamp not specific enough

I am new to solr and I have a quite basic question about delta-imports. I
have several new records by second in my mySQL DB. So when I start an
import at second x it is very possible, that I will get some new records
in the DB at the very same second after starting the import, but the next
time when I start a delta-import it will check the "last_index_time" in
dadaaimport.properties and will import all the records changed after this
second x. So I will lose all records which have been changed in second x
after starting the last import. And if I am right, it would be same issue
even if it is possible to cahange the timestamp from seconds to e.g.
milliseconds. The timewindow would be smaller, the amount of lost records
would be smaller, but the problem itself would still be there.
I have not found any mention of this issue in the tutorials or anywhere
else for that matter. Am I the first one who deals with several records
per second, or do i miss something else?
Many thanks in Advance!

I fill the login form and click on submit button and page is reloaded and email id is blank how to get email id text filled?

I fill the login form and click on submit button and page is reloaded and
email id is blank how to get email id text filled?

I fill the login form called email id and password and click on submit
button and page is reloaded and email id is blank how to get email id text
filled?

Sunday, 1 September 2013

How to create an Document template and then Converting to PDF?

How to create an Document template and then Converting to PDF?

I would like to create a document template and then process this template
(adding specific information) to export the result via PDF.
Do you know the best way to handle pdf documents? I have syncfussion library.

how to lock device but prevent the screen to be turned off in android?

how to lock device but prevent the screen to be turned off in android?

I'm using DevicePolicyManager to lock the device while needed. what I want
is to bring up the lock screen but using DevicePolicyManager and calling
it's method lockNow() will lock the device and turn the screen off. how to
prevent turning off the screen?

spool out put to particular file from command prompt

spool out put to particular file from command prompt

i want to spool my out put to particular file .my database in sql server.i
given code in command prompt like this: first i am connecting to my data
base like this: sqlcmd -S SUPPORT2/SUPPORT2 -U sa -P solutions
SUPPORT2/SUPPORT2 is a my server name then i am giving my databse
name(vallett)
then i am taking Ename from EmployeeMaster_tbl i want to spool this out
put to particular word file how i can do this?