[Tutor] Tkinter Copy/Paste/Cut functionalities

Pooja Bhalode poojabhalode11 at gmail.com
Fri Feb 3 21:34:22 EST 2017


Hi,

I am new to tkinter and looking for some help with select/copy/paste
functionalities. I wish to keep these tabs in the Edit menu and as well as
be able to do it using the shortcut keys.
Here, I am trying to create a GUI and needed some help with that.
I came across some snippets of the code to do this but using a self class.
I was wondering if some one could help me create these functionalities in a
manner similar to the following code. (similar to the Quitcommand
function).

Another question I had, was how to make the status bar text as a variable
such that it keeps on displaying what is going on in the program?

I would really appreciate your help on this.
Thank you so much.

Pooja

Code:

from Tkinter import *
import datetime
import tkMessageBox

root = Tk()
root.title("Name of the interface")

def Doit():
   print "Inside the function"

from tkMessageBox import *

def Quitcommand():
    if askyesno('Verify', 'Are you sure you want to quit?'):
        if askyesno('Save file', 'Do you want to save the current file?'):
            print 'Saving file'
        root.quit()
    else:
        showinfo('Quit not implemented.')

def LoadNew():
    print 'Loading new .gPROMS files'
    # User enters the name of the to be executed.
    if tkMessageBox.askyesno('Reading new file','Do you want to read
in the new files'):
        print 'Reading new files. '

def show_about():
    print 'HELP function'

from tkFileDialog import askopenfilename

def OpenFile():
    name = askopenfilename()
    print name

### --- Menu bar ---- ####
menu = Menu(root)
root.config(menu=menu)

editmenu = Menu(menu, tearoff=0)
menu.add_cascade(label="Edit", menu=editmenu)

editmenu.add_command(label="Cut",accelerator="Ctrl+X",command=DoCut)
editmenu.add_command(label="Copy",accelerator="Ctrl+C",command=DoCopy)
editmenu.add_command(label="Paste", accelerator="Ctrl+V"command=DoPaste)
editmenu.add_command(label="Make Changes", command=TimeAllowed)
editmenu.add_command(label="Line", command=Doit)


### --- Status bar ---- ####
Status = Label(root, text = 'Static',bd=1, relief=SUNKEN, anchor=W)
Status.pack(side=BOTTOM, fill=X)



root.mainloop()


More information about the Tutor mailing list