Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:38:59+00:00 2026-05-27T18:38:59+00:00

Hii I have a requirement of calling the variable in function which is having

  • 0

Hii I have a requirement of calling the variable in function which is having it declaration and definition in another function.Could any one help me please.

import sys
import os
import tkMessageBox
from Tkinter import *
from tkCommonDialog import Dialog
import shutil
import tkFileDialog
import win32com.client

win = Tk()
win.title("Copying the Directory to specified location")
win.geometry("600x600+200+50")
win.resizable()
global src
global des
class Copy():
    #global src
    #global des
    def __init__(self):
        def srce():
            src = tkFileDialog.askdirectory(title = "The source folder is ")
            textboxsrc.delete(0,END)
            textboxsrc.insert(0,src)
            print src
            return src

        textboxsrc = Entry(win, width="70")
        textboxsrc.insert(0,'Enter master file name')
        textboxsrc.pack()
        textboxsrc.place(relx=0.40, rely=0.06, anchor=CENTER)
        bu = Button(text = "Source",font = "Verdana 12 italic bold",bg = "Purple",fg= "white", command= srce)
        bu.pack(fill =X, expand=YES)
        bu.place(relx=0.85, rely=0.06, anchor=CENTER)

        def dest():
            des = tkFileDialog.askdirectory(title = "TheDestination folder is ")
            textboxdes.delete(0,END)
            textboxdes.insert(0,des)
            print des
            return des

        textboxdes = Entry(win, width="70")
        textboxdes.insert(0,'Enter master file name')
        textboxdes.pack()
        textboxdes.place(relx=0.40, rely=0.13, anchor=CENTER)
        bu1 = Button(text = "Destination",font = "Verdana 12 italic",bg = "Purple",fg= "white", command= dest)
        bu1.pack(fill =X, expand=YES)
        bu1.place(relx=0.85, rely=0.13, anchor=CENTER)

        def start():
            #global src
            #global des
            #abc = os.path.dirname(src)
            #dgh = os.path.dirname(des)
            try:
                shutil.copy(src,des)
            except :
                tkMessageBox.showwarning("Copying file",  "Error while copying\n(%s)" )

        bn =Button(text = "Copy",font = "Verdana 12 italic", bg = "Purple",fg= "white",command=start)
        bn.pack(fill =X, expand = YES)
        bn.place(relx=0.50, rely=0.25, anchor=CENTER)

obj= Copy()
#obj.source(win)
#obj.destination(win)
win.mainloop()

Here,I get an error in the start() function. giving me the problem of accepting src and des variable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:39:00+00:00Added an answer on May 27, 2026 at 6:39 pm

    i updated your code (and made the corrections needed after reading your feedback) to use class variables/attributes and fixed your error message, check it out. Please note, using class variables means you can only use this class as a singleton, only one of these classes can be used at a time because every instance would use the same Copy.src, Copy.des, Copy.textboxsrc and Copy.textboxdsc variables.

    import sys
    import os
    import tkMessageBox
    from Tkinter import *
    from tkCommonDialog import Dialog
    import shutil
    import tkFileDialog
    import win32com.client
    
    win = Tk()
    win.title("Copying the Directory to specified location")
    win.geometry("600x600+200+50")
    win.resizable()
    
    # force "new" Python class by inheriting from "object"
    class Copy(object):
    
        # use class attributes for shared variables
        src = None
        des = None
        textboxsrc = None
        textboxdes = None
    
        def srce():
            # access the class attributes via "Copy." syntax
            Copy.src = tkFileDialog.askdirectory(title = "The source folder is ")
            Copy.textboxsrc.delete(0,END)
            Copy.textboxsrc.insert(0,Copy.src)
            print Copy.src
            return Copy.src
    
        textboxsrc = Entry(win, width="70")
        textboxsrc.insert(0,'Enter master file name')
        textboxsrc.pack()
        textboxsrc.place(relx=0.40, rely=0.06, anchor=CENTER)
        bu = Button(text = "Source",font = "Verdana 12 italic bold",bg = "Purple",fg= "white", command= srce)
        bu.pack(fill =X, expand=YES)
        bu.place(relx=0.85, rely=0.06, anchor=CENTER)
    
        def dest():
            # access the class attributes via "Copy." syntax
            Copy.des = tkFileDialog.askdirectory(title = "TheDestination folder is ")
            Copy.textboxdes.delete(0,END)
            Copy.textboxdes.insert(0,Copy.des)
            print Copy.des
            return Copy.des
    
        textboxdes = Entry(win, width="70")
        textboxdes.insert(0,'Enter master file name')
        textboxdes.pack()
        textboxdes.place(relx=0.40, rely=0.13, anchor=CENTER)
        bu1 = Button(text = "Destination",font = "Verdana 12 italic",bg = "Purple",fg= "white", command= dest)
        bu1.pack(fill =X, expand=YES)
        bu1.place(relx=0.85, rely=0.13, anchor=CENTER)
    
        def start():
            # access the class attributes via "Copy." syntax
            print "copy src(%s) to des(%s)" % (Copy.src,Copy.des)
            try:
                shutil.copy(Copy.src,Copy.des)
            except:
                tkMessageBox.showwarning("Copying file",  "Error while copying\n(%s) to (%s)\n%s\n%s"
                % (Copy.src,Copy.des, sys.exc_info()[0], sys.exc_info()[1]) )
    
    
        bn =Button(text = "Copy",font = "Verdana 12 italic", bg = "Purple",fg= "white",command=start)
        bn.pack(fill =X, expand = YES)
        bn.place(relx=0.50, rely=0.25, anchor=CENTER)
    
    obj= Copy()
    win.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hii every one i have created a data entry screen like this in which
hii, I am using devexpress xtrascheduler.In this i have created one custom form which
hii all..i have some code that make all string characters which have been input
Hi i have a requirement where i have to use a tools API which
Hi I have the following requirement. I want to create variable number of String
hii... I am making a view based application in which I have tabbar controller
Hi I have such requirement, but I don't know whether it could be implemented
Hii....i am new to iPhone programming..Can anybody help me out please i have an
Hi I am trying to deploy an application using webstart. I have a requirement
Hii , I have a small php form. I need it to come in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.