This topic is READ ONLY
Bennjamin (27) [Avatar] Offline
I am trying to make a PythonCard program where you can change the font size while running the program by moving a slider, but i don't know how it works because the TextArea's font attribute is some weird list in {} brackets. it looks like this:
{'faceName': u'MS Shell Dlg 2', 'family': 'sansSerif', 'size': 8}
i want to know how to change the number next to 'size' within the program so the font size will change while you move the slider!
How do i do this?? I really Need help!
warren.sande (211) [Avatar] Offline
Re: PythonCard
I'm not sure it's possible to dynamically change the font size in a TextArea. I'll do some digging and get back to you.

By the way, the weird list with the {} is a Python "dictionary" We didn't cover dictionaries in the book, but it's another way of collecting things together (like a list), except you store pairs of items. Each pair is called a "key-value pair" and you use the keys to find values.

I'm working on a blog post about dictionaries, but if you Google "python dictionary" I'm sure you'll find lots of information about them.

Warren Sande
Bennjamin (27) [Avatar] Offline
Re: PythonCard
I looked up dictionaries, and tried changing the value using this code:
def on_FontSize_mouseDrag(self, event):
self.components.DataSet.font['size'] = self.components.FontSize.value
(FontSize is a Slider)
but got an error saying:
Traceback (most recent call last):
File "", line 408, in _dispatch
handler(background, aWxEvent)
File "Csmilieython25", line 20, in on_FontSize_mouseDrag
self.components.DataSet.font['size'] = self.components.FontSize.value
TypeError: 'Font' object does not support item assignment

I'm guessing that means that in some instances, Python actually DOES enforce data hiding??
P.S. I know the forum strips whitespace, just give me your e-mail and i'll send the code to you.
warren.sande (211) [Avatar] Offline
Re: PythonCard
As you might have gleaned from the error message, 'font' is not a dictionary, but rather an object. It happens that the font's parameters are stored in a dictionary, but you cannot change them by directly modifying the dictionary. There is, however, a method for changing the font size.

Here's a complete (although simplified) Pythoncard program that will do what you want. The file is not included, but it has just two components, the TextArea and the Slider
(I'll use dots to indicate the leading whitespace)

from PythonCard import model
class MainWindow(model.Background):
....def on_Slider1_mouseUp(self, event):
........sliderValue = self.components.Slider1.value
........font = self.components.TextArea1.GetFont()

app = model.Application(MainWindow)

Warren Sande
Bennjamin (27) [Avatar] Offline
Re: PythonCard
Thank you.