add view class
This commit is contained in:
1
frontend/views/__init__.py
Normal file
1
frontend/views/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .number import NumberView
|
||||
24
frontend/views/base.py
Normal file
24
frontend/views/base.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from tkinter import ttk, Frame, Canvas
|
||||
|
||||
class View(Frame):
|
||||
|
||||
def __init__(self, *args, tare_command=None, calibrate_command=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.actions = Frame(self)
|
||||
self.actions.pack()
|
||||
# self.calibrate_button = ttk.Button(self.actions, text="Calibrate", command=calibrate_command)
|
||||
# self.calibrate_button.pack()
|
||||
self.tare_button = ttk.Button(self.actions, text="Tare", command=tare_command)
|
||||
self.tare_button.pack()
|
||||
|
||||
self.canvas = Canvas(self, width=144, height=168, background='white')
|
||||
self.canvas.pack()
|
||||
|
||||
self._init_canvas()
|
||||
|
||||
def _init_canvas(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def update_weight(self, weight: float):
|
||||
raise NotImplementedError()
|
||||
9
frontend/views/number.py
Normal file
9
frontend/views/number.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from .base import View
|
||||
|
||||
class NumberView(View):
|
||||
|
||||
def _init_canvas(self):
|
||||
self.label = self.canvas.create_text(50, 68, text="0.0 g", font=("Arial", 18), fill='black', justify='left')
|
||||
|
||||
def update_weight(self, weight):
|
||||
self.canvas.itemconfig(self.label, text=f"{weight:.1f} g")
|
||||
Reference in New Issue
Block a user