QNA > C > Come Fare Un'applicazione Di Elaborazione Testi Con Python

Come fare un'applicazione di elaborazione testi con python

I dizionari saranno molto utili. Questo è Python 3.7 ma funzionerà bene in 2.7 cambiando tkinter in Tkinter e perdendo il ttk. Questo esempio è di definizioni ma potete farlo convertire in quello che volete.

  1. from tkinter import * 
  2. from tkinter import ttk 
  3. words = {'acre': 'An English measurement for a Lot of land', 
  4. 'aurora': 'A bright hue over the northern hemisphere', 
  5. 'absolom': 'An Israelite King from the Bible', 
  6. 'acrobat': 'Someone who performs dangerous stunts', 
  7. 'aircraft': 'Man made things that fly', 
  8. 'aristotle': 'Some old pencil pusher', 
  9. 'ape': 'A bully', 
  10. 'abba': 'A 1980 glamour band'} 
  11.  
  12. def calculate(*args): 
  13. prova: 
  14. value = int(word.get())#CHECKS IF Word is a number ! 
  15. word_out.set('Word must not be a number !') 
  16. except ValueError: 
  17. try: 
  18. value = str(word.get()) 
  19. value = words.get(value) 
  20. if value == None:# CHECKS IF WORD NOT IN DICTIONARY 
  21. word_out.set('Word not listed !') 
  22. else: 
  23. word_out.set(value+'.') 
  24. except ValueError: 
  25. pass 
  26.  
  27. root=Tk() 
  28. width = root.winfo_screenwidth()# USE if using WINDOWS 
  29. height = root.winfo_screenheight() 
  30. #root.geometry(str(width) + "x" + str(height))# WINDOWS 
  31. root.geometry('900x500') 
  32. root.title("Word Processor") 
  33. mainframe = ttk.Frame(root, padding="13 13 12 12") 
  34. mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) 
  35. mainframe.columnconfigure(0, weight=1) 
  36. mainframe.rowconfigure(0, weight=1) 
  37.  
  38. word = StringVar() 
  39. word_out = StringVar() 
  40.  
  41. word_entry = ttk.Entry(mainframe, width=12, textvariable = word) 
  42. word_entry.grid(column=1, row=0, sticky=(W, E)) 
  43.  
  44. ttk.Label(mainframe, textvariable = word_out).grid(column=1, row=2, sticky=(W, E)) 
  45. ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=2, row=0, sticky=W) 
  46.  
  47. ttk.Label(mainframe, text="Enter Word").grid(column=0, row=0, sticky=W) 
  48. ttk.Label(mainframe, text="Definition:").grid(column=0, row=2, sticky=E) 
  49. #ttk.Label(mainframe, text="Definition").grid(column=3, row=2, sticky=W) 
  50.  
  51. for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5) 
  52.  
  53. word_entry.focus() 
  54. root.bind('', calculate) 
  55.  
  56. root.mainloop() 

If your dictionaries get too large place them into separate .py files and import them as filename.function() and inside the function() place the dictionary and return it as named.

  1. inside filename 
  2. def funtioname(): 
  3. words = {'words':'values',etc} 
  4. return words 
  5. -------------------------------------------- 
  6. imp tkinter etc. then 
  7. import filename 
  8. inside calculate add and replace--> 
  9.  
  10. value = str(word.get()) 
  11. lib = filename.functionname() 
  12. value = lib.get(value) 
  13.  
  14. do the app 

Di Bethina Turbyfill

Quando LG G8 ThinQ sarà lanciato in India? :: Come memorizzare l'input dell'utente usando il mio bot discord.py
Link utili