473,416 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How to inser (anyting I print) to the textbox (TKinter) ?try but it hang? pleas help

17
when I wont to inser (anyting I print) to the textbox it will not inser
it just print then hanging

Expand|Select|Wrap|Line Numbers
  1. # a look at the Tkinter Text widget
  2.  
  3. # use ctrl+c to copy, ctrl+x to cut selected text,
  4.  
  5. # ctrl+v to paste, and ctrl+/ to select all
  6.   # count words in a text and show the first ten items
  7. # by decreasing frequency
  8.  
  9. import Tkinter as tk
  10. import os, glob
  11. import sys
  12. import string
  13. import re
  14. import tkFileDialog      
  15. def most_frequant_word():    
  16. browser= tkFileDialog.askdirectory()
  17. #browser= os.listdir(a)
  18.  
  19.  
  20. for root, dirs, files in os.walk(browser):
  21.     print 'Looking into %s' % root.split('\\')[-1]
  22.     print 'Found %d dirs and %d files' % (len(dirs), len(files))
  23.     #text1.insert(tk.INSERT,'Looking into %s' % root.split('\\')[-1])
  24.     #text1.insert(tk.INSERT, 'Found %d dirs and %d files' % (len(dirs), len(files)))
  25.     for idx, file in enumerate(files):
  26.      print 'File #%d: %s' % (idx + 1, file)
  27.       #text1.insert(tk.INSERT, 'File #%d: %s' % (idx + 1, file))
  28.      ff = open (os.path.join(root, file), "r")
  29.      text = ff.read ( )
  30.      ff.close ( )
  31.      word_freq = {}
  32.  
  33.      word_list = text.strip().split()
  34.  
  35.      for word in word_list:
  36.       word = word.lower().rstrip('.,/"-_;\\[]()')
  37.  
  38.       if word.isalpha():
  39.                 # build the dictionary
  40.        count = word_freq.get(word, 0)
  41.        word_freq[word] = count + 1
  42.  
  43.        # create a list of (freq, word) tuples
  44.        freq_list = [(freq, word) for word, freq in word_freq.items()]
  45.  
  46.        # sort the list by the first element in each tuple (default)
  47.        freq_list.sort(reverse=True)
  48.  
  49.      for n, tup in enumerate(freq_list):
  50.     # print the first ten items
  51.       if n < 50:
  52.         print "%s times: %s" % tup
  53.         text1.insert(tk.INSERT, freq)
  54.         text1.insert(tk.INSERT, word)
  55.         text1.insert(tk.INSERT, "\n")
  56.  
  57. raw_input('\nHit enter to exit')
  58.  
  59. root = tk.Tk(className = " most_frequant_word")
  60. # text entry field, width=width chars, height=lines text
  61. v1 = tk.StringVar()
  62. text1 = tk.Text(root, width=50, height=20, bg='green')
  63. text1.pack()
  64. # function listed in command will be executed on button click
  65. button1 = tk.Button(root, text='Brows', command=most_frequant_word)
  66. button1.pack(pady=5)
  67. text1.focus()
  68. root.mainloop()
code try to insert to the textbox
Expand|Select|Wrap|Line Numbers
  1. print "%s times: %s" % tup
  2.         text1.insert(tk.INSERT, freq)
  3.         text1.insert(tk.INSERT, word)
  4.         text1.insert(tk.INSERT, "\n")
when I wont to insert file name and directory to the textbox it will hang also
code is comment
Expand|Select|Wrap|Line Numbers
  1. print 'Looking into %s' % root.split('\\')[-1]
  2.     print 'Found %d dirs and %d files' % (len(dirs), len(files))
  3.     #text1.insert(tk.INSERT,'Looking into %s' % root.split('\\')[-1])
  4.     #text1.insert(tk.INSERT, 'Found %d dirs and %d files' % (len(dirs), len(files)))
  5.     for idx, file in enumerate(files):
  6.      print 'File #%d: %s' % (idx + 1, file)
  7.       #text1.insert(tk.INSERT, 'File #%d: %s' % (idx + 1, file))
Mar 21 '08 #1
2 2666
jlm699
314 100+
Please stop spamming the forum with multiple posts of the same question. It would also be very helpful if you could clarify your questions further, as they are not always easy to understand.

Your problem here is that you are not adapting the code that we have provided for you to work for your own purposes. You're simply copying and pasting without bothering to understand what the code is doing.

I have fixed the code that you posted, but I won't bother posting it. After figuring out the blatant syntax errors, all I had to do was remove the raw_input("Hit enter to exit") line. Which leads me to believe you didn't take the time to figure out what purpose that line served.

Additionally, "frequant" and "brows" should be frequent and browse.
Mar 21 '08 #2
alivip
17
Firstly thank you very much for your help

Secondly I am really sorry for madding you angry

Thirdly I promise I will not do it again
Mar 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Russell E. Owen | last post by:
I want to support execution of simple user-written scripts in a Tkinter application. The scripts should be able to wait for data and such without hanging the GUI (and without having to write the...
3
by: Philippe C. Martin | last post by:
Hi, I need to pop-up in a "modless" manner some windows from an existing Tkinter loop. The following code works OK under Linux: the second window opens, shows the information, and quits cleanly...
2
by: import newbie | last post by:
Hi all, I'm a programming dabbler trying learn Python, and I've got a few questions. Mainly: Where can I find a good open-source library or tutorial (preferably free) that explains how to...
3
by: musosdev | last post by:
Hi guys Okay, I've setup my projects to open and compile fine in VS2005 using FPSE and remote web, but it's *really* slow. So I thought I'd have a go at doing it the normal way, by loading from...
4
by: arvind | last post by:
How to pass the variables defined inside the function to the another function on click event of the button in Tkinter? pleas send me a sample code if anybody has it. thanx
5
by: Ben Kovitz | last post by:
Hi, I just tried to run Tkinter on OS X 10.3.9 under Python 2.4.3, and I'm getting a bus error as soon as I call Tk(). Googling has turned up info other Tkinter bus errors, but not this one that...
1
by: flash | last post by:
Need hlep to delete array only because all function is ok (inser, sort andsearch) #include <iostream.h> //functions prototype void Insert(int,int); void Delete(int,int); int...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
0
by: Guilherme Polo | last post by:
On 10/29/08, Olrik Lenstra <o.lenstra@gmail.comwrote: It will be a combination of commands, not a single one. Initially I considered this as "probably without solution", since tcl acquired a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.