| | |
Help
Thread Solved
![]() |
•
•
Join Date: Mar 2006
Posts: 12
Reputation:
Solved Threads: 0
I have been looking over Vegaseat's Word Count program. I have two thoughts about what I want to configure it to do, but I'm not sure how to go about it.
Idea 1; This is most important. I want users to be able to put a text file in the same folder as the program, then the user can input 'Random.txt' or whatever the name is, and the program does its thing.
Idea 2; I want to make a graphical interface. I guess it would be a system of check input and doing it.
JB
Idea 1; This is most important. I want users to be able to put a text file in the same folder as the program, then the user can input 'Random.txt' or whatever the name is, and the program does its thing.
Idea 2; I want to make a graphical interface. I guess it would be a system of check input and doing it.
JB
Which code snippet are you thinking of?
Wordcount of a text file (Python)
http://www.daniweb.com/code/snippet238.html
or
Word Frequency in a Text String (Python)
http://www.daniweb.com/code/snippet374.html
Wordcount of a text file (Python)
http://www.daniweb.com/code/snippet238.html
or
Word Frequency in a Text String (Python)
http://www.daniweb.com/code/snippet374.html
May 'the Google' be with you!
This would be the simplest way:
Using a file dialog window to get a filename can be as simple as this with Tkinter:
Just incorporate this within the snippet code and you are set.
Python Syntax (Toggle Plain Text)
filename = raw_input("Enter the name of the textfile (eg. test.txt): ")
Python Syntax (Toggle Plain Text)
import tkFileDialog filename = tkFileDialog.askopenfilename(filetypes=[("Text files","*.txt")]) print filename # for testing
May 'the Google' be with you!
•
•
Join Date: Mar 2006
Posts: 12
Reputation:
Solved Threads: 0
Well I've decided to rewrite into a simpler version like this:
I have a few more questions:
1. I can't figure out for the life of me how to go about splitting the word count onto one line, character count on another etc. Does anyone know how? EDIT: Solved. Now it's perfect in that respect.
And 2. I want to try and write it so that it doesn't rely upon the python shell, but upon tkinter, like a window.
3. I want it to quit the tkinter window when done.
4. I want to package it into an executable.
If anyone can help it would be appreciated.
Edit: Added code tags vegaseat
Python Syntax (Toggle Plain Text)
#!/usr/bin/python import sys import tkFileDialog filename = tkFileDialog.askopenfilename(filetypes=[("Text files","*.txt")]) print filename try: file = open(filename) except IOError, why: print 'Unable to open file.\n', why sys.exit(-1) charCount = lineCount = wordCount = 0 for line in file.xreadlines(): lineCount += 1 wordCount += len(line.split()) charCount += len(line) print "Number of lines:" print lineCount, print "Number of Words:" print wordCount, print "Number of characters:" print charCount
I have a few more questions:
1. I can't figure out for the life of me how to go about splitting the word count onto one line, character count on another etc. Does anyone know how? EDIT: Solved. Now it's perfect in that respect.
And 2. I want to try and write it so that it doesn't rely upon the python shell, but upon tkinter, like a window.
3. I want it to quit the tkinter window when done.
4. I want to package it into an executable.
If anyone can help it would be appreciated.
Edit: Added code tags vegaseat
Last edited by vegaseat; Mar 26th, 2006 at 9:51 am.
Graphics User Interface (GUI) programming isn't too difficult in Python, but you have to get used to the typical window widgets like buttons, frames, labels, entries, grids and so on.
My initial advice to you:
Get very familiar with the rudimentary Python syntax before you tackle GUI programming.
If I find some time, I will post a typical Tkinter template containing a button to load the file and a set of labels to show the result.
My initial advice to you:
Get very familiar with the rudimentary Python syntax before you tackle GUI programming.
If I find some time, I will post a typical Tkinter template containing a button to load the file and a set of labels to show the result.
May 'the Google' be with you!
![]() |
Other Threads in the Python Forum
- Previous Thread: Problem extracting values of a Dictionary
- Next Thread: Sorting in Python
| Thread Tools | Search this Thread |
abrupt accessdenied advanced ansi anti apache application approximation argv array backend beginner binary builtin calculator change command converter countpasswordentry csv curved dan08 def dictionary edit event file float format function google heads homework inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook pointer prime programming py2exe pygame pyopengl python random recursion redirect remote return reverse scrolledtext session software sprite statictext statistics string strings syntax terminal text thread threading time tlapse tuple twoup ubuntu unicode unit urllib urllib2 variable voip wordgame write wxpython






