Im posting a python program and need to convert it to C++ language. import Tkint
ID: 3806820 • Letter: I
Question
Im posting a python program and need to convert it to C++ language.
import Tkinter
import Tkinter as tk
from Tkinter import *
import time
def current_iso8601():
"""Get current date and time in ISO8601"""
# https://en.wikipedia.org/wiki/ISO_8601
# https://xkcd.com/1179/
return time.strftime("%m.%d.%Y DATE %H:%M:%S TIME")
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.pack()
self.createWidgets()
def tstampIn(self):
clockFile = open("clockTracker.txt","w")
print "You have successfuly Clocked In "
clockIn = time.strftime("%m.%d.%Y DATE %H:%M:%S TIME, CLOCK IN ")
print clockIn
clockFile.write(clockIn)
clockFile.close
def tstampOut(self):
clockFile = open("clockTracker.txt", "a")
print "You have successfuly Clocked Out "
clockOut = time.strftime("%m.%d.%Y DATE %H:%M:%S TIME, CLOCK OUT ")
print clockOut
clockFile.write(clockOut)
clockFile.close
def LstampIn(self):
clockFile = open("clockTracker.txt", "a")
print "You have successfuly Clocked Out for LUNCH "
lunchIn = time.strftime("%m.%d.%Y DATE %H:%M:%S TIME, LUNCH STARTED ")
print lunchIn
clockFile.write(lunchIn)
clockFile.close
def LstampOut(self):
clockFile = open("clockTracker.txt", "a")
print "You have successfuly Clocked In from LUNCH "
lunchOut = time.strftime("%m.%d.%Y DATE %H:%M:%S TIME, LUNCH ENDED ")
print lunchOut
clockFile.write(lunchOut)
clockFile.close
def createWidgets(self):
self.now = tk.StringVar()
self.time = tk.Label(self, font=('Helvetica', 24))
self.time.pack(side="top")
self.time["textvariable"] = self.now
self.t_stamp = Button(self, fg="green")
self.t_stamp["text"] = "CLOCK IN"
self.t_stamp["command"] = self.tstampIn
self.t_stamp.pack(side="top")
self.t_stamp = Button(self, fg="blue")
self.t_stamp["text"] = "LUNCH BEGIN"
self.t_stamp["command"] = self.LstampIn
self.t_stamp.pack(side="left")
self.t_stamp = Button(self, fg="green")
self.t_stamp["text"] = "LUNCH END"
self.t_stamp["command"] = self.LstampOut
self.t_stamp.pack(side="right")
self.t_stamp = Button(self, fg="blue")
self.t_stamp["text"] = "CLOCK OUT"
self.t_stamp["command"] = self.tstampOut
self.t_stamp.pack(side="bottom")
self.QUIT = tk.Button(self, text="QUIT", fg="red",
command=root.destroy)
self.QUIT.pack(side="bottom")
# initial time display
self.onUpdate()
def onUpdate(self):
# update displayed time
self.now.set(current_iso8601())
# schedule timer to call myself after 1 second
self.after(1000, self.onUpdate)
root = tk.Tk()
app = Application(master=root)
root.mainloop()
Explanation / Answer
This program is difficult to convert to C++ . The reasons are mentioned below.
1. TkInter is used in this Code. It is related to GUI
2. C++ don't have native GUI API library. Based on the Platform(Windows/Linux) there are some OS specific toolkits will be there like GTK etc. We have to use third party libraries like Qt or WxWidgets etc to program GUI. They are licenced. :(