灵感来自Bryan Oakley的帖子[问题] Switch between two frames in tkinter 我用三个页面编写了这个程序,每个页面都有一个动画:一个时钟,一个测量设备,最后一页上的三个条形图。 执行该程序后,我发现它在Windows和Linux上增加了内存和CPU利用率。我使用Python 2.7。 我确定我错了,但我还没有找到如何将内存和CPU使用百分比保持在一个恒定的水平。 欢迎任何建议。感谢。
以下是代码:
#import tkinter as tk # python3
import Tkinter as tk # python
import time
import datetime
import os
import random
from math import *
TITLE_FONT = ("Helvetica", 18, "bold")
LABPOZ4 = 480
LABVERT = 5
if (os.name == 'nt'):
cale = 'images\\gif\\'
elif (os.name == 'posix'):
cale = 'images/gif/'
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo, PageThree):
page_name = F.__name__
frame = F(container, self)
self.frames[page_name] = frame
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
#frame.winfo_toplevel().overrideredirect(1) #pentru teste se comenteaza
frame.winfo_toplevel().geometry("640x480")
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is the start page", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
# DATA SI TIMPUL
DataOra = tk.StringVar()
DataOra.set('2016-04-06 16:20:00')
label4 = tk.Label(self, textvariable=DataOra, fg='blue', bg='white', relief="ridge", width=20)
label4.config(font=('courier', 10, 'bold'))
label4.place(x=LABPOZ4, y=LABVERT)
button1 = tk.Button(self, text="Go to\nPage One", height=2, width=10,
command=lambda: controller.show_frame("PageOne"))
button2 = tk.Button(self, text="Go to\nPage Two", height=2, width=10,
command=lambda: controller.show_frame("PageTwo"))
button3 = tk.Button(self, text="Go to\nPage Three", height=2, width=10,
command=lambda: controller.show_frame("PageThree"))
button1.place(x=100,y=430)
button2.place(x=200,y=430)
button3.place(x=300,y=430)
def afisare():
date1=datetime.datetime.now().strftime("%Y-%m-%d")
time1=datetime.datetime.now().strftime("%H:%M:%S")
tmx= '%s %s' % (date1, time1)
DataOra.set(tmx)
label4.after(1000,afisare)
afisare()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 1", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
# DATA SI TIMPUL
DataOra = tk.StringVar()
DataOra.set('2016-04-06 16:20:00')
label4 = tk.Label(self, textvariable=DataOra, fg='blue', bg='white', relief="ridge", width=20)
label4.config(font=('courier', 10, 'bold'))
label4.place(x=LABPOZ4, y=LABVERT)
button = tk.Button(self, text="Go to the\n start page", height=2, width=10,
command=lambda: controller.show_frame("StartPage"))
button.place(x=100,y=430)
# CEAS TEST
def Clock0(w, nx, ny): # clock draw function
x0 = nx/2; lx = 9*nx/20 # center and half-width of clock face
y0 = ny/2; ly = 9*ny/20
r = 5
r0 = 0.9 * min(lx,ly) # distance of hour labels from center
r1 = 0.6 * min(lx,ly) # length of hour hand
r2 = 0.8 * min(lx,ly) # length of minute hand
w.create_oval(x0-lx, y0-ly, x0+lx, y0+ly, width=3) # clock face
for i in range(1,13): # label the clock face
phi = pi/6 * i # angular position of label
x = x0 + r0 * sin(phi) # Cartesian position of label
y = y0 - r0 * cos(phi)
w.create_text(x, y, text=str(i)) # hour label
t = time.localtime() # current time
t_s = t[5] # seconds
t_m = t[4] + t_s/60 # minutes
t_h = t[3] % 12 + t_m/60 # hours [0,12]
phi = pi/6 * t_h # hour hand angle
x = x0 + r1 * sin(phi) # position of arrowhead
y = y0 - r1 * cos(phi) # draw hour hand
w.create_line(x0, y0, x, y, arrow=tk.LAST, fill="red", width=5)
phi = pi/30 * t_m # minute hand angle
x = x0 + r2 * sin(phi) # position of arrowhead
y = y0 - r2 * cos(phi) # draw minute hand
w.create_line(x0, y0, x, y, arrow=tk.LAST, fill="blue", width=4)
phi = pi/30 * t_s # second hand angle
x = x0 + r2 * sin(phi) # position of arrowhead
y = y0 - r2 * cos(phi)
w.create_line(x0, y0 , x, y, arrow=tk.LAST, fill="yellow", width=3) # draw second hand
centru_ace = w.create_oval(x0-r,y0-r,x0+r,y0+r, fill="red")
def Clock(w, nx, ny): # clock callback function
w.delete(tk.ALL) # delete canvas
Clock0(w, nx, ny) # draw clock
w.after(10, Clock, w, nx, ny) # call callback after 10 ms
nx = 250; ny = 250 # canvas size
w = tk.Canvas(self, width=nx, height=ny, bg = "white") # create canvas w
w.place(x=200,y=50) # make canvas visible
Clock(w, nx, ny)
### END CEAS TEST
def afisare():
date1=datetime.datetime.now().strftime("%Y-%m-%d")
time1=datetime.datetime.now().strftime("%H:%M:%S")
tmx= '%s %s' % (date1, time1)
DataOra.set(tmx)
label4.after(1000,afisare)
afisare()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 2", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
# DATA SI TIMPUL
DataOra = tk.StringVar()
DataOra.set('2016-04-06 16:20:00')
label4 = tk.Label(self, textvariable=DataOra, fg='blue', bg='white', relief="ridge", width=20)
label4.config(font=('courier', 10, 'bold'))
label4.place(x=LABPOZ4, y=LABVERT)
button = tk.Button(self, text="Go to the\nstart page", height=2, width=10,
command=lambda: controller.show_frame("StartPage"))
button.place(x=100,y=430)
# APARAT TEST
global red, bulina
red = 0
bulina = 0
def Aparat0(w, nx, ny, valoare): # clock draw function
global red, bulina
x0 = nx/2; lx = 9*nx/20 # center and half-width of clock face
y0 = ny/2+14; ly = 9*ny/20
r1 = 0.8 * min(lx,ly) # length of indicator
t_h = valoare # 90 jos, 45 stanga, 180 sus
phi = pi/6 * t_h # hand angle
x = x0 + r1 * sin(phi) # position of arrowhead
y = y0 - r1 * cos(phi) # draw hand
red = w.create_line(x0, y0, x, y, arrow=tk.LAST, fill="red", width=3)
r = 5
bulina = w.create_oval(x0-r,y0-r,x0+r,y0+r, fill="red")
def Aparat(w, nx, ny, valoare): # clock callback function
global red, bulina
w.delete(red) # delete canvas
w.delete(bulina)
Aparat0(w, nx, ny, valoare) # draw clock
w.after(5000, Aparat, w, nx, ny, valoare) # call callback after 10 ms
# IMAGINE SCALA APARAT
photo4 = tk.PhotoImage(file=cale+'scala1.gif') #scala1.gif
self.ph1 = photo4
nx = 350; ny = 350 # canvas size
w = tk.Canvas(self, width=nx, height=ny, bg = "white") # create canvas w
w.create_image(175, 175, image=photo4)
w.place(x=150,y=50) # make canvas visible
#Aparat(w, nx, ny, 180)
def afisare_Aparat():
valoare = random.randint(100,270)
Aparat(w,nx,ny,valoare)
w.after(5000,afisare_Aparat)
afisare_Aparat()
### END APARAT TEST
def afisare():
date1=datetime.datetime.now().strftime("%Y-%m-%d")
time1=datetime.datetime.now().strftime("%H:%M:%S")
tmx= '%s %s' % (date1, time1)
DataOra.set(tmx)
label4.after(1000,afisare)
afisare()
class PageThree(tk.Frame): # Parametrii AC
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 3", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
# DATA SI TIMPUL
DataOra = tk.StringVar()
DataOra.set('2016-04-06 16:20:00')
label4 = tk.Label(self, textvariable=DataOra, fg='blue', bg='white', relief="ridge", width=20)
label4.config(font=('courier', 10, 'bold'))
label4.place(x=LABPOZ4, y=LABVERT)
button = tk.Button(self, text="Go to the\nstart page", height=2, width=10,
command=lambda: controller.show_frame("StartPage"))
button.place(x=100,y=430)
# APARAT TEST
global red1
red1 = 0
bulina1 = 0
def Aparat01(w1, nx, ny, valoare): # bar draw function
global red1
x0 = 50
y0 = ny
for i in range(0,450,50):
x = 20 # Cartesian position of label
y = y0 - i/2 - 5
#print y
w1.create_text(x, y, text=str(i)) # value label
w1.create_line(x+20, y, x+15, y, fill="black", width=2)
t_h = valoare # valoare
x = x0 + 20 # position of head
y = y0 - t_h # draw bar
red1 = w1.create_rectangle(x0, y0, x, y, fill="red")
w1.create_line(50, 200, 71, 200, fill="green", width=4)
def Aparat1(w1, nx, ny, valoare): # bar callback function
global red1
w1.delete(tk.ALL) # delete canvas
Aparat01(w1, nx, ny, valoare) # draw bar
w1.after(3000, Aparat1, w1, nx, ny, valoare) # call callback after 5000 ms
nx = 70; ny = 350 # canvas size
w1 = tk.Canvas(self, width=nx, height=ny, bg = "white", relief='ridge') # create canvas
w1.place(x=150,y=50) # make canvas visible at x,y
def afisare_Aparat1():
valoare = random.randint(100,270)
Aparat1(w1,nx,ny,valoare)
w1.after(3000,afisare_Aparat1)
afisare_Aparat1()
### END APARAT TEST
# APARAT TEST1
global red2
red2 = 0
def Aparat02(w2, nx, ny, valoare): # clock draw function
global red2
x0 = 50 # center and half-width of clock face
y0 = ny # length of indicator
for i in range(0,450,50):
x = 20 # Cartesian position of label
y = y0 - i/2 - 5
#print y
w2.create_text(x, y, text=str(i)) # value label
w2.create_line(x+20, y, x+15, y, fill="black", width=2)
t_h = valoare # 90 jos, 45 stanga, 180 sus
x = x0 + 20 # position of arrowhead
y = y0 - t_h # draw hand
red2 = w2.create_rectangle(x0, y0, x, y, fill="blue")
w2.create_line(50, 200, 71, 200, fill="yellow", width=4)
def Aparat2(w2, nx, ny, valoare): # clock callback function
global red2
w2.delete(tk.ALL) # delete canvas
Aparat02(w2, nx, ny, valoare) # draw clock
w2.after(4000, Aparat2, w2, nx, ny, valoare) # call callback after 10 ms
nx2 = 70; ny2 = 350 # canvas size
w2 = tk.Canvas(self, width=nx2, height=ny2, bg = "white", relief='ridge') # create canvas w
w2.place(x=250,y=50) # make canvas visible
def afisare_Aparat2():
valoare = random.randint(100,270)
Aparat2(w2,nx,ny,valoare)
w2.after(4000,afisare_Aparat2)
afisare_Aparat2()
### END APARAT TEST1
# APARAT TEST2
global red3
red3 = 0
def Aparat03(w3, nx, ny, valoare): # clock draw function
x0 = 50 # center and half-width of clock face
y0 = ny # length of indicator
for i in range(0,450,50):
x = 20 # Cartesian position of label
y = y0 - i/2 - 5
#print y
w3.create_text(x, y, text=str(i)) # value label
w3.create_line(x+20, y, x+15, y, fill="black", width=2)
t_h = valoare # 90 jos, 45 stanga, 180 sus
x = x0 + 20 # position of arrowhead
y = y0 - t_h # draw hand
red3 = w3.create_rectangle(x0, y0, x, y, fill="green")
w3.create_line(50, 200, 71, 200, fill="red", width=4)
def Aparat3(w3, nx, ny, valoare): # clock callback function
global red3
w3.delete(tk.ALL) # delete canvas
Aparat03(w3, nx, ny, valoare) # draw clock
w3.after(5000, Aparat3, w3, nx, ny, valoare) # call callback after 10 ms
nx3 = 70; ny3 = 350 # canvas size
w3 = tk.Canvas(self, width=nx3, height=ny3, bg = "white", relief='ridge') # create canvas
w3.place(x=350,y=50) # make canvas visible
def afisare_Aparat3():
valoare = random.randint(100,270)
Aparat3(w3,nx,ny,valoare)
w3.after(5000,afisare_Aparat3)
afisare_Aparat3()
### END APARAT TEST2
def afisare():
date1=datetime.datetime.now().strftime("%Y-%m-%d")
time1=datetime.datetime.now().strftime("%H:%M:%S")
tmx= '%s %s' % (date1, time1)
DataOra.set(tmx)
label4.after(1000,afisare)
afisare()
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
答案 0 :(得分:0)
最后,我发现了问题。如果有人有兴趣,这是正确的代码。我尽可能地简化了代码。谢谢你的建议。
#import tkinter as tk # python3
import Tkinter as tk # python
import time
import datetime
import os
import random
from math import *
TITLE_FONT = ("Helvetica", 18, "bold")
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo, PageThree):
page_name = F.__name__
frame = F(container, self)
self.frames[page_name] = frame
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
#frame.winfo_toplevel().overrideredirect(1) #pentru teste se comenteaza
frame.winfo_toplevel().geometry("640x480")
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is the start page", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
# DATA SI TIMPUL
DataOra = tk.StringVar()
DataOra.set('2016-04-06 16:20:00')
label4 = tk.Label(self, textvariable=DataOra, fg='blue', bg='white', relief="ridge", width=20)
label4.config(font=('courier', 10, 'bold'))
label4.place(x=480, y=5)
button1 = tk.Button(self, text="Go to\nPage One", height=2, width=10,
command=lambda: controller.show_frame("PageOne"))
button2 = tk.Button(self, text="Go to\nPage Two", height=2, width=10,
command=lambda: controller.show_frame("PageTwo"))
button3 = tk.Button(self, text="Go to\nPage Three", height=2, width=10,
command=lambda: controller.show_frame("PageThree"))
button1.place(x=100,y=430)
button2.place(x=200,y=430)
button3.place(x=300,y=430)
def afisare():
date1=datetime.datetime.now().strftime("%Y-%m-%d")
time1=datetime.datetime.now().strftime("%H:%M:%S")
tmx= '%s %s' % (date1, time1)
DataOra.set(tmx)
label4.after(1000,afisare)
afisare()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 1", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
# DATA SI TIMPUL
DataOra = tk.StringVar()
DataOra.set('2016-04-06 16:20:00')
label4 = tk.Label(self, textvariable=DataOra, fg='blue', bg='white', relief="ridge", width=20)
label4.config(font=('courier', 10, 'bold'))
label4.place(x=430, y=5)
button = tk.Button(self, text="Go to the\n start page", height=2, width=10,
command=lambda: controller.show_frame("StartPage"))
button.place(x=100,y=430)
# CEAS TEST
global line1, line2, line3
line1 = 0; line2 = 0; line3 = 0
def Clock0(w, nx, ny): # clock draw function
global line1, line2, line3
x0 = nx/2; lx = 9*nx/20 # center and half-width of clock face
y0 = ny/2; ly = 9*ny/20
r = 5
r0 = 0.9 * min(lx,ly) # distance of hour labels from center
r1 = 0.6 * min(lx,ly) # length of hour hand
r2 = 0.8 * min(lx,ly) # length of minute hand
w.create_oval(x0-lx, y0-ly, x0+lx, y0+ly, width=3) # clock face
for i in range(1,13): # label the clock face
phi = pi/6 * i # angular position of label
x = x0 + r0 * sin(phi) # Cartesian position of label
y = y0 - r0 * cos(phi)
w.create_text(x, y, text=str(i)) # hour label
t = time.localtime() # current time
t_s = t[5] # seconds
t_m = t[4] + t_s/60 # minutes
t_h = t[3] % 12 + t_m/60 # hours [0,12]
phi = pi/6 * t_h # hour hand angle
x = x0 + r1 * sin(phi) # position of arrowhead
y = y0 - r1 * cos(phi) # draw hour hand
line1 = w.create_line(x0, y0, x, y, arrow=tk.LAST, fill="red", width=5, tag='ceas')
w.coords(line1, x0, y0, x, y)
phi = pi/30 * t_m # minute hand angle
x = x0 + r2 * sin(phi) # position of arrowhead
y = y0 - r2 * cos(phi) # draw minute hand
line2 = w.create_line(x0, y0, x, y, arrow=tk.LAST, fill="blue", width=4, tag='ceas')
w.coords(line2, x0, y0, x, y)
phi = pi/30 * t_s # second hand angle
x = x0 + r2 * sin(phi) # position of arrowhead
y = y0 - r2 * cos(phi)
line3 = w.create_line(x0, y0 , x, y, arrow=tk.LAST, fill="yellow", width=3, tag='ceas')
w.coords(line3, x0, y0, x, y)
centru_ace = w.create_oval(x0-r,y0-r,x0+r,y0+r, fill="red")
def Clock(w, nx, ny): # clock callback function
global line1, line2, line3
w.delete('ceas') # delete canvas
Clock0(w, nx, ny)
#w.coords(line1, 100,100,200,200) # draw clock
#w.coords(line2, 100,100,200,200)
#w.coords(line3, 100,100,200,200)
w.after(10, Clock, w, nx, ny) # call callback after 10 ms
nx = 250; ny = 250 # canvas size
w = tk.Canvas(self, width=nx, height=ny, bg = "white") # create canvas w
w.place(x=200,y=50) # make canvas visible
Clock(w, nx, ny)
### END CEAS TEST
def afisare():
date1=datetime.datetime.now().strftime("%Y-%m-%d")
time1=datetime.datetime.now().strftime("%H:%M:%S")
tmx= '%s %s' % (date1, time1)
DataOra.set(tmx)
label4.after(1000,afisare)
afisare()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 2", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
# DATA SI TIMPUL
DataOra = tk.StringVar()
DataOra.set('2016-04-06 16:20:00')
label4 = tk.Label(self, textvariable=DataOra, fg='blue', bg='white', relief="ridge", width=20)
label4.config(font=('courier', 10, 'bold'))
label4.place(x=480, y=5)
button = tk.Button(self, text="Go to the\nstart page", height=2, width=10,
command=lambda: controller.show_frame("StartPage"))
button.place(x=100,y=430)
# APARAT TEST
global red, bulina
red = 0
bulina = 0
def Aparat0(w, nx, ny, valoare): # scale draw function
global red, bulina
x0 = nx/2; lx = 9*nx/20 # center and half-width of clock face
y0 = ny/2+14; ly = 9*ny/20
r1 = 0.8 * min(lx,ly) # length of indicator
t_h = valoare # 90 jos, 45 stanga, 180 sus
phi = pi/6 * t_h # hand angle
x = x0 + r1 * sin(phi) # position of arrowhead
y = y0 - r1 * cos(phi) # draw hand
red = w.create_line(x0, y0, x, y, arrow=tk.LAST, fill="red", width=3)
r = 5
bulina = w.create_oval(x0-r,y0-r,x0+r,y0+r, fill="red")
def Aparat(w, nx, ny, valoare): # callback function
global red, bulina
w.delete(red) # delete red, bulina
w.delete(bulina)
Aparat0(w, nx, ny, valoare) # draw clock
#####w.after(5000, Aparat, w, nx, ny, valoare) ###### PROBLEM !!!
nx = 350; ny = 350 # canvas size
w = tk.Canvas(self, width=nx, height=ny, bg = "white") # create canvas w
w.place(x=150,y=50) # make canvas visible
#Aparat(w, nx, ny, 180)
def afisare_Aparat():
valoare = random.randint(100,270)
Aparat(w,nx,ny,valoare)
w.after(1000,afisare_Aparat)
afisare_Aparat()
### END APARAT TEST
def afisare():
date1=datetime.datetime.now().strftime("%Y-%m-%d")
time1=datetime.datetime.now().strftime("%H:%M:%S")
tmx= '%s %s' % (date1, time1)
DataOra.set(tmx)
label4.after(1000,afisare)
afisare()
class PageThree(tk.Frame): # Parametrii AC
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 3", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
# DATA SI TIMPUL
DataOra = tk.StringVar()
DataOra.set('2016-04-06 16:20:00')
label4 = tk.Label(self, textvariable=DataOra, fg='blue', bg='white', relief="ridge", width=20)
label4.config(font=('courier', 10, 'bold'))
label4.place(x=480, y=5)
button = tk.Button(self, text="Go to the\nstart page", height=2, width=10,
command=lambda: controller.show_frame("StartPage"))
button.place(x=100,y=430)
# APARAT TEST
def Aparat01(w1, nx, ny, valoare): # bar draw function
#global red1
x0 = 50
y0 = ny
for i in range(0,450,50):
x = 20 # Cartesian position of label
y = y0 - i/2 - 5
#print y
w1.create_text(x, y, text=str(i)) # value label
w1.create_line(x+20, y, x+15, y, fill="black", width=2)
t_h = valoare # valoare
x = x0 + 20 # position of head
y = y0 - t_h # draw bar
w1.create_rectangle(x0, y0, x, y, fill="red")
w1.create_line(50, 200, 71, 200, fill="green", width=4)
def Aparat1(w1, nx, ny, valoare): # bar callback function
w1.delete(tk.ALL) # delete canvas
Aparat01(w1, nx, ny, valoare) # draw bar
######w1.after(3000, Aparat1, w1, nx, ny, valoare) ###### PROBLEM !!!!
nx = 70; ny = 350 # canvas size
w1 = tk.Canvas(self, width=nx, height=ny, bg = "white", relief='ridge') # create canvas
w1.place(x=150,y=50) # make canvas visible at x,y
def afisare_Aparat1():
valoare = random.randint(100,270)
Aparat1(w1,nx,ny,valoare)
w1.after(1000,afisare_Aparat1)
afisare_Aparat1()
### END APARAT TEST
def afisare():
date1=datetime.datetime.now().strftime("%Y-%m-%d")
time1=datetime.datetime.now().strftime("%H:%M:%S")
tmx= '%s %s' % (date1, time1)
DataOra.set(tmx)
label4.after(1000,afisare)
afisare()
if __name__ == "__main__":
app = SampleApp()
app.mainloop()