I have a modified version of Burkhard Meier's Button factory that needs to be extended with a text field factory. I need to follow the below structure:
Expected output:
import tkinter as tk
from tkinter import ttk
from tkinter import Menu
class ButtonFactory():
def createButton(self, type_):
return buttonTypes[type_]()
class ButtonBase():
relief ='flat'
foreground ='white'
def getButtonConfig(self):
return self.relief, self.foreground
class ButtonRidge(ButtonBase):
relief ='ridge'
foreground ='red'
class ButtonSunken(ButtonBase):
relief ='sunken'
foreground ='blue'
class ButtonGroove(ButtonBase):
relief ='groove'
foreground ='green'
buttonTypes = [ButtonRidge, ButtonSunken, ButtonGroove]
Is the below a correct extension of the above code to create a concrete Entry widget Factory class with a fFactory method called generateText(..)
? My instructions say tkinter textfields are Entry
widgets.
class TextFactory():
def generateText(self):
sv=tk.StringVar()
tx = factory.generateText(0).getTextConfig()[0]
sv.set(tx)
bg = factory.generateText(0).getTextConfig()[1]
action = tk.Entry(self.widgetFactory, textvariable=sv, background=bg, foreground="white")
action.grid(column=1, row=1)'''
Is there a Python ninja out there that could help me understand how to do the above and also how to:
-
Create an abstract product named
TextBase()
that will have default attributestextvariable
andbackground
? -
Declare a
getTextConfig(...)
method. -
Create 3 concrete text products named
text_1
/2
/3
/ that will be assignedtextvariable
values ‘type red / type blue / type green” as shown in the image below. -
Extend the OOP class with
createTextFields()
method that creates a factory object. -
I’ve been given the below code as well but I don’t know how to implement it to solve the above.
#Entry field 1 sv=tk.StringVar() tx = factory.createText(0).getTextConfig()[0] sv.set(tx) bg = factory.createText(0).getTextConfig()[1] action = tk.Entry(self.widgetFactory, textvariable=sv, background=bg, foreground="white") action.grid(column=1, row=1)
Aucun commentaire:
Enregistrer un commentaire