Apr-03-2021, 06:37 PM
Just wanted to show current progress. Rewrote the code a little. The next step is to figure out how I want to do the die.
#! /usr/bin/env python3 # Do the imports import wx class Header(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id, size=(800, 60)) self.Bind(wx.EVT_PAINT, self.OnPaint) def OnPaint(self, event): font = wx.Font(25, wx.ROMAN, wx.ITALIC, wx.BOLD) self.SetBackgroundColour('ivory') dc = wx.PaintDC(self) dc.SetFont(font) dc.DrawText('wxPython Yahtzee', 250, 10) self.SetForegroundColour('darkorange') dc = wx.PaintDC(self) dc.SetFont(font) dc.DrawText('wxPython Yahtzee', 251, 11) self.SetForegroundColour(wx.Colour(50, 50, 50)) class Footer(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id, size=(800, 30)) self.Bind(wx.EVT_PAINT, self.OnPaint) def OnPaint(self, event): font = wx.Font(12, wx.ROMAN, wx.ITALIC, wx.BOLD) self.SetBackgroundColour('ivory') dc = wx.PaintDC(self) dc.SetFont(font) dc.DrawText('My-Python.org', 350, 5) self.SetForegroundColour('darkorange') dc = wx.PaintDC(self) dc.SetFont(font) dc.DrawText('My-Python.org', 351, 6) self.SetForegroundColour(wx.Colour(50, 50, 50)) class Card(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id, size=(400, 475)) self.Bind(wx.EVT_PAINT, self.OnPaint) self.section = { 'ones': None, 'twos': None, 'threes': None, 'fours': None, 'fives': None, 'sixes': None, 'upper score': None, 'bonus': None, 'upper total': None, '3 of a kind': None, '4 of a kind': None, 'sm. straight': None, 'lg. straight': None, 'fullhouse': None, 'yahtzee': None, 'chance': None, 'lower score': None, 'upper score': None, 'grand total': None } def OnPaint(self, event): colored_rows = ['upper score', 'bonus', 'upper total', 'lower score'] self.SetBackgroundColour('white') self.SetForegroundColour('black') i = 5 j = 8 for label, score in self.section.items(): if score == None: score = '' dc = wx.PaintDC(self) dc.SetPen(wx.Pen('black')) if label in colored_rows: dc.SetBrush(wx.Brush('light yellow')) elif label == 'grand total': dc.SetBrush(wx.Brush('light blue')) else: dc.SetBrush(wx.Brush('gray', wx.TRANSPARENT)) dc.DrawRectangle(10, i, 250, 25) dc.DrawRectangle(261, i, 50, 25) dc.DrawText(label.upper(), 15, j) dc.DrawText(score, 275, j) i += 26 j += 26 class Die(wx.Panel): def __init__(self, parent, id ,number): wx.Panel.__init__(self, parent, id) self.Bind(wx.EVT_PAINT, self.OnPaint) self.number = number def OnPaint(self, event): dc = wx.PaintDC(self) dc.SetPen(wx.Pen(wx.BLACK)) dc.SetBrush(wx.Brush('ivory2')) dc.DrawRectangle(10, 10, 50,50) dc.SetBrush(wx.Brush('black')) dc.DrawCircle(34.5, 34.5, 5) class MainWindow(wx.Frame): def __init__(self, parent, id): wx.Frame.__init__(self, parent, -1, 'Yahtzee', size=(800, 600)) sizer = wx.GridBagSizer(vgap=2, hgap=2) header = Header(self, wx.ID_ANY) card = Card(self, wx.ID_ANY) die = Die(self, wx.ID_ANY, number=1) footer = Footer(self, wx.ID_ANY) sizer.Add(header, pos=(0,0), flag=wx.EXPAND, span=(1, 2)) sizer.Add(card, pos=(1, 0), flag=wx.EXPAND) sizer.Add(die, pos=(1, 1), flag=wx.EXPAND) sizer.Add(footer, pos=(2,0), flag=wx.EXPAND, span=(1, 2)) self.SetSizerAndFit(sizer) def main(): app = wx.App(False) window = MainWindow(None, wx.ID_ANY) window.Show() app.MainLoop() if __name__ == '__main__': main()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags