Python Forum
pythonscript for translation into Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pythonscript for translation into Tkinter
#1
I would like to translate this pythonscript to Tkinter.
I got this python script from youtube and I searched for a similar Tkinterscript on the internet but couldn't find anything.
I also have some Ebooks from Tkinter, but I don't have a similar Tkinter script.
Is there anyone who can translate this script for me into a Tkinter script

 fh = open ("c:\Worddatabase\info.txt ", "r")
word = input("Enter word to search:")
s = " "
count = 1
L = fh.readlines()
for i in L:
    L2 = i.split()
    if word in L2:
        print ("Line number", count,":",i)
    count+=1
Reply
#2
Please make an attempt, we'll will help but you should try first.
Reply
#3
Here's my shot a translating to tkinter:
import tkinter
fh = open ("c:\Worddatabase\info.txt ", "r")
word = input("Enter word to search:")
s = " "
count = 1
L = fh.readlines()
for i in L:
    L2 = i.split()
    if word in L2:
        print ("Line number", count,":",i)
    count+=1
Or were you looking for something different? Why do you want this very straightforward and easy to use script reworked to have a GUI which I honestly think would be harder to use and generally less useful. Instead of trying to tack a GUI on this thing I would go the other direction and turn it into something that can take command line arguments.

But if you want to make a GUI the first thing you need to do is storyboard the user interface. How does the user enter information. How are the results displayed? Once you know that you can start thinking about the code. What tkinter widgets work like the controls in your storyboard? How are those widgets created and configured? How do you respond to user input from the controls?
Reply
#4
I found this python script on the internet and I did fix some typing errors. But I tried everything but I can't figure it out.
The intention is that with searching a word that it prints the line number in the gui but also the meaning of it is found
# -*- coding: utf-8 -*-

from tkinter import *
import tkinter as tk
import re

def find():
    word = entry.get() 
    filename = ("info.txt") 
    fin=open(filename,'r')
    
    

    for line in fin:
          
        line = line.rstrip()
        worde=re.findall("\S+"+word+"\S+|"+word+"\S+|"+"\S+"+word,line)
        


     
    result.configure(text=worde)
    result2.configure(text="Number: "+str(len(worde)))
       
    #Basic interface with Tkinter
root = tk.Tk()

root.title("Find Word")
root.geometry('800x300')

wordTK=tk.Label(text="Word:")
wordTK.grid(row=0,column=0)

entry=tk.Entry()
entry.grid(row=0,column=1)


button = tk.Button(text='Bul', command=find)
button.grid(row=1,column=1)

result=tk.Label(text="  ")
result.grid(row=2,column=1)

result2=tk.Label(text="  ")
result2.grid(row=3,column=1)


    

root.mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Kivy] Kivy UI language translation lib mikepy 2 1,162 Feb-11-2023, 02:12 PM
Last Post: mikepy
  [PyQt] Linux - Application translation not load when run from .desktop launcher dancaer69 2 2,257 May-19-2019, 06:01 PM
Last Post: dancaer69

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020