PalaniKasi
Posts: 52
Joined: Mon Dec 14, 2015 1:51 pm

Making button and text widgets using tkinter

Wed Apr 20, 2016 1:49 pm

guys
i want to create two buttons..when i press the button it will list contents in text widget in tkinter

DirkS
Posts: 10015
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Making button and text widgets using tkinter

Wed Apr 20, 2016 2:22 pm

PalaniKasi wrote:guys
i want to create two buttons..when i press the button it will list contents in text widget in tkinter
Great. Have fun!

Or is there a question somewhere in there?

User avatar
RogerW
Posts: 286
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Making button and text widgets using tkinter

Wed Apr 20, 2016 3:25 pm

Where are you going to get the text from? You say two buttons but it looks more like you need one button and a textbox.

PalaniKasi
Posts: 52
Joined: Mon Dec 14, 2015 1:51 pm

Re: Making button and text widgets using tkinter

Thu Apr 21, 2016 4:20 am

when i press the button it should display content of one memory card in the GUI text window

scotty101
Posts: 3750
Joined: Fri Jun 08, 2012 6:03 pm

Re: Making button and text widgets using tkinter

Thu Apr 21, 2016 8:41 am

Code: Select all

from tkinter import *
from os import listdir
from os.path import isfile, join
from os import getcwd

class App(Frame):
    def __init__(self,parent=None,**kw):
        Frame.__init__(self,parent,**kw)
        self.btnGetFiles = Button(self,text="Get Files",command=self.getFiles)
        self.btnGetFiles.grid()
        self.etrFileList = Text(self)
        self.etrFileList.grid()

    def getFiles(self):
        # Keep next line to return all files in the current folder
        mypath = getcwd()
        # Uncomment next line to specify which folder to get the contents of
        #mypath = '/home/pi/myfolder'
        files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
        for file in files:
            self.etrFileList.insert(END,file)
            self.etrFileList.insert(END,"\n")
        

if __name__ == '__main__':
    root = Tk()
    App(root).grid()
    root.mainloop()
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

PalaniKasi
Posts: 52
Joined: Mon Dec 14, 2015 1:51 pm

Re: Making button and text widgets using tkinter

Fri Apr 22, 2016 11:13 am

Thanks dude..
I need one more help..how can i copy files from one pendrive to another pendrive in GUI..File selection should also be there..

scotty101
Posts: 3750
Joined: Fri Jun 08, 2012 6:03 pm

Re: Making button and text widgets using tkinter

Fri Apr 22, 2016 11:44 am

You use a file explorer like the one that comes with raspbian rather than writing your own GUI...

but you really feel that you need to do it in your own python GUI then try something like what is proposed here
http://stackoverflow.com/questions/1231 ... -in-python
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Return to “Python”