In Python -- Modify the solution to Practice Problem 9.3 so that the times are d
ID: 3768941 • Letter: I
Question
In Python -- Modify the solution to Practice Problem 9.3 so that the times are displayed in a separate pop up window.
def greenwich():
'prints Greenwich day and time info'
time = strftime('Day: %d %b %Y Time: %H:%M:%S %p ', gmtime())
print('Greenwich time ' + time)
def local():
'prints local day and time info'
time = strftime('Day: %d %b %Y Time: %H:%M:%S %p ', localtime())
print('Local time ' + time)
# Local time button
buttonl = Button(root, text='Local time', command=local)
buttonl.pack(side=LEFT)
# Greenwich mean time button
buttong = Button(root,text='Greenwich time', command=greenwich)
buttong.pack(side=RIGHT)
Explanation / Answer
Sample code:
Sample output:
Code to copy:
#!/usr/bin/python
#import time package
import time
import tkinter
# import message box
import tkinter.messagebox
#code to dispaly greenwich mean time in pop up window
tkinter.messagebox.showinfo("Greenwich time",time.strftime('Day: %d %b %Y Time: %H:%M:%S %p ',time.gmtime()))
#code to dispaly local time in pop up window
tkinter.messagebox.showinfo("Local time",time.strftime('Day: %d %b %Y Time: %H:%M:%S %p ',time.localtime()))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.