reading(printing to screen) program

Reply

Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

reading(printing to screen) program

 
0
  #1
Oct 3rd, 2005
I was helping my 6 year old read some sentenses he learned in school. for example:

the dog is on skates
the bird is on a plane
the pig rides the horse

I noticed he was not really reading(kind of) the individual words, he had the whole sentenses memorized. When I used the words he knew, but in a different order, he has to try much harder to make out the sentenses. This forses him to sound out each individual word.

I came up with a neat idea for a python program. As he learns new words I could put them into a different lists: one list containing verbs, another containing nouns. then have the program generate random sentenses. This would be easy to do if i was just outputing the words to the terminal. The problem with that is, they are small to read.

I would like some ideas on outputting the sentense the script generates to a window with larger text, maybe even specific font I choose. So eveytime I press enter, or click on the window, a new sentense will be displayed across the monitor.

Would tkinter, gtkgame, wxpython would be the easiest(or best). This seems like a nice simple way to learn some basic gui stuff. Any suggestions would be appreciated.
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,009
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 929
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: reading(printing to screen) program

 
0
  #2
Oct 3rd, 2005
You know this is a wonderful project. I remember when my son was about four, I wrote a hangman game where he had to guess rather simple words. He just loved that game. By the time he got to school, he was way ahead in spelling.

Here is one idea, put the text on a button, you click it and it changes ...
[php]# display a random sentence from a list in colorful Tkinter

from Tkinter import *
import random

black = '#000000'
blue = '#0000FF'
red = '#FF0000'
yellow = '#FFFF00'
lime = '#00FF00'

sentenceList = ['the dog is on skates', 'the bird is on a plane', 'the pig rides the horse']

def setText():
str1 = random.choice(sentenceList)
push1.config(text=str1)


#create the form
form1 = Tk()
# set the form's title
form1.title('Random Text')
# create a button
push1 = Button(form1, text='Click to set new text .............', command=setText)
# configure the button's text font and colors
push1.config(height=3, font=('times', 20, 'bold'), fg=black, bg=yellow)
# pack the button into the frame
push1.pack(expand=YES, fill=BOTH)
# start the event loop (run the program)
form1.mainloop()
[/php]
Pick the font, size and colors you want.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: reading(printing to screen) program

 
0
  #3
Oct 3rd, 2005
Thanks, I will examine your code later :-) I will let you know it gos
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,009
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 929
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: reading(printing to screen) program

 
0
  #4
Oct 3rd, 2005
The Tkinter GUI would be my choice for short fun programs like that. Our friend mawe is an expert on Tkinter, so he might have better ideas.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: reading(printing to screen) program

 
0
  #5
Oct 3rd, 2005
I just ran your program as you wrote it, it is perfect, as far as the output goes. When I have some time, I will make a random sentense generator, kind of madlib like.
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 133
Reputation: mawe is an unknown quantity at this point 
Solved Threads: 58
mawe mawe is offline Offline
Junior Poster

Re: reading(printing to screen) program

 
0
  #6
Oct 3rd, 2005
Hi!

Here is a version with a canvas:
  1. from Tkinter import *
  2. import random
  3.  
  4. sentence_list = [
  5. "the dog is on skates",
  6. "the bird is on a plane",
  7. "the pig rides the horse",
  8. "one more senseless sentence"
  9. ]
  10.  
  11. def draw_text():
  12. text = random.choice(sentence_list)
  13. c.delete("all")
  14. c.create_text(250,100,text=text,font="times 30 bold")
  15.  
  16. root = Tk()
  17. c = Canvas(width=500,height=200,bg="white")
  18. c.pack()
  19. Button(text="Next Text", command=draw_text).pack()
  20. root.mainloop()

Regards, mawe
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: reading(printing to screen) program

 
0
  #7
Oct 3rd, 2005
cool, I really like that. I will probably use it :-)

thanks guys



**rambling**
man python is great. you can do such nice stuff with next to no code, or programming experience.
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 137
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: reading(printing to screen) program

 
0
  #8
Oct 3rd, 2005
**rambling**
man python is great. you can do such nice stuff with next to no code, or programming experience.

--- and it is so easy to experiment with the codes!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: reading(printing to screen) program

 
0
  #9
Oct 10th, 2005
here is wht I came up with. thanks mawe for your code :-) is their a max size I can set the font?

  1. #!/usr/bin/env python
  2. #
  3. # readit
  4. #
  5. from Tkinter import *
  6. import random
  7. adj = ('red', 'green', 'yellow', 'blue', 'pink', 'orange', 'purple')
  8. numbers = ( 'one','one','one','one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine')
  9. animals = ('bird', 'teacher', 'cow', 'goat', 'pig', 'dog', 'duck', 'cat', 'sister', 'grandmother', 'friend')
  10. phrase = ('is in a car', 'is on a bike', 'is in a boat', 'is on a train', 'is on skates', 'is on a plane', 'is on a horse')
  11. have = ('school','teacher','classroom','table','book','work')
  12.  
  13. # I have %s(numbers) %s(adj) %s(have)%s(either "" or 's')
  14. format1 = "I have %s %s %s%s"
  15.  
  16. # The %s(number) %s(animals)%s(either "", or 's') %(phrase)
  17. format2 = "%s %s%s %s."
  18.  
  19. def choices():
  20. radj = random.choice(adj)
  21. rnumbers = random.choice(numbers)
  22. ranimals = random.choice(animals)
  23. rphrase = random.choice(phrase)
  24. rhave = random.choice(have)
  25. return radj, rnumbers, ranimals, rphrase, rhave
  26.  
  27. def one_format(choice):
  28. ret = choice
  29. if ret[1] != 'one':
  30. quant = 's.'
  31. else:
  32. quant = '.'
  33. return format1%(ret[1],ret[0],ret[4],quant)
  34.  
  35. def second_format(choice):
  36. ret = choice
  37. if ret[1] != 'one':
  38. quant = 's'
  39. else:
  40. quant = ""
  41. sentence = format2%(ret[1].title(),ret[2],quant,ret[3])
  42. if quant == 's':
  43. sentence = sentence.replace(' is ',' are ')
  44. return sentence
  45.  
  46. def make_sentence():
  47. if random.choice(range(2)) == 0:
  48. return second_format(choices())
  49. else:
  50. return one_format(choices())
  51.  
  52. # this following code was giving to me my mauve
  53. # I changed the sizes around a bit
  54. def draw_text():
  55. text = make_sentence()
  56. c.delete("all")
  57. c.create_text(500,100,text=text,font="arial 100 bold")
  58.  
  59. root = Tk()
  60. c = Canvas(width=1000,height=200,bg="white")
  61. c.pack()
  62. Button(text="Next Text", command=draw_text).pack()
  63. root.mainloop()
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: reading(printing to screen) program

 
0
  #10
Oct 10th, 2005
strange, on linux my font will only get so large, no matter what number I set it at. even if I set it at 60, it seems to get no larger then it does if I set it at 30.

On windows the font seems to get larger and larger. If I set it to 60 the sentences will not even fit on the screen.

I am not sure why it is not working correctly with linux
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC