1 year ago
#379266
Crypric_Athena
wxPython: How can I display time into my wxFrame?
I am trying to make a program that displays stock information and displays the total loss or gain and the date and time. It is for a python assignment and I have been working on this part alone for a while and can not figure it out. This is the code I have.
import wx
import sqlite3
import requests
import datetime
class MyDialog(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, title="Dialog")
lbl = wx.StaticText(self, label='Read Data', pos=(120, 10))
self.com = wx.TextCtrl(self, -1, '', pos=(30, 40))
wx.StaticText(self, -1, 'Company', pos=(150, 40))
self.sym = wx.TextCtrl(self, -1, '', (30, 80))
wx.StaticText(self, -1, 'Symbol', (150, 80))
self.pur = wx.TextCtrl(self, -1, '', (30, 120))
wx.StaticText(self, -1, 'Purchase Price', (150, 120))
self.cur = wx.TextCtrl(self, -1, '', (30, 160))
wx.StaticText(self, -1, 'Current Price', (150, 160))
self.sha = wx.TextCtrl(self, -1, '', pos=(200, 40))
wx.StaticText(self, -1, 'Shares', pos=(320, 40))
self.gl = wx.TextCtrl(self, -1, '', pos=(200, 80))
wx.StaticText(self, -1, 'Gain/Loss', pos=(330, 80))
okBtn = wx.Button(self, id=wx.ID_OK, pos=(135, 200))
class DataList(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(600, 560))
panel = wx.Panel(self, -1)
self.lbl0 = wx.StaticText(self.panel, label="Name", pos=(20, 24))
self.table_name = wx.StaticText(panel, -1, pos=(60, 5))
self.list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT, pos=(20, 30), size=(550, 420))
# set up columns
self.list.InsertColumn(0, 'Company', width=100)
self.list.InsertColumn(1, 'Symbol', width=90)
self.list.InsertColumn(2, 'Purchase Price', width=90)
self.list.InsertColumn(3, 'Current Price', width=90)
self.list.InsertColumn(4, 'Shares', width=90)
self.list.InsertColumn(5, 'Gain/Loss', width=90)
# set up buttons
display = wx.Button(panel, -1, 'Display', size=(-1, 30), pos=(80, 470))
cancel = wx.Button(panel, -1, 'Cancel', size=(-1, 30), pos=(400, 470))
display.Bind(wx.EVT_BUTTON, self.OnDisplay)
cancel.Bind(wx.EVT_BUTTON, self.OnCancel)
def OnDisplay(self, event):
try:
self.getAllData()
except lite.Error as error:
dlg = wx.MessageDialog(self, str(error), 'Error occured')
dlg.ShowModal()
def OnCancel(self, event):
self.Close() # exit program
app = wx.App()
dl = DataList(None, -1, 'Read Data')
dl.Show()
app.MainLoop()
This is the code that was given to me to use.
x = datetime.datetime.now() # date and time date = x.strftime("%A %B %d, %Y : %H:%M")
python
wxpython
0 Answers
Your Answer