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 6036839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:59:02+00:00 2026-05-23T05:59:02+00:00

The following is a function I created, and put it in a file called

  • 0

The following is a function I created, and put it in a file called last_function.py

from tkinter import*


def new_gui(app,sound_file,mixer):

    track=mixer.Sound(sound_file)
    def track_toggle():
        if ballCheckbutton.get()==1:

            track.play(loops=-1)
        else:
            track.stop()

    ballCheckbutton=IntVar()    
    c1=Checkbutton(app,text="check me out",command=track_toggle,variable=ballCheckbutton)
    c1.pack(side=LEFT)

    ballScale=DoubleVar()

    def ScaleVolume(v):
        track.set_volume(ballScale.get())

    ballScale.set(track.get_volume())
    s1=Scale(app,variable=ballScale,resolution=0.1,command=ScaleVolume,orient=HORIZONTAL,from_=0.0,to=1.0,label="volume")
    s1.pack()

and this is the file i use.. to call the code and run it..

from tkinter import *
import pygame.mixer
from last_function import*

app=Tk()
mixer=pygame.mixer
mixer.init()
new_gui(app,"49119_M_RED_HardBouncer.wav",mixer)


def close():
    mixer.stop()
    app.destroy()

app.protocol("WM_DELETE_WINDOW",close)
app.mainloop()

Everything works fine.. but my query is…

1> Why can’t I remove from tkinter import* from the last_function file.. cause anyway it’s got that on the top of the file that’s calling it right. Why do I get an error saying IntVar() not defined.

2> Why do I have to pass mixer as a parameter in the function? can the function not inherit it directly from import pygame.mixerthat’s on top of the file calling it?
What I mean to say is. THERE ARE TKINTER COMPONENTS ALSO BEING USED, BUT I DON’T PASS TKINTER AS A PARAMETER.. Do I ! then why is there this… selective parameter assignment??

I’m really confused!!!

  • 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-23T05:59:03+00:00Added an answer on May 23, 2026 at 5:59 am

    1> Why can’t i remove from tkinter
    import* from the last_function file..
    cause anyway it’s got that on the top
    of the file that’s calling it
    right.Why do i get an error saying
    IntVar() not defined

    The Python “import” follows the same scoping rules as the rest of the Python language. By “import” at the top of your second files does not make the Tkinter namespace available to the last_function.py module. Tkinter also needs to be imported there.

    2>why do i have to pass mixer as a
    parameter in the function? can the
    function not inherit it directly from
    import pygame.mixerthat’s on top of
    the file calling it? WHAT I MEAN TO
    SAY IS. THERE ARE TKINTER COMPONENTS
    ALSO BEING USED,BUT I DON’T PASS
    TKINTER AS A PARAMETER.. DO I!! then
    why is there this.. selective
    parameter assignment??

    With the way you have this coded, you need to pass mixer because you are modifying it in your second file with:

    mixer.init()
    

    If you reimported mixer in your last_function.py, you would be getting another instance of mixer and not the one previously imported. There is nothing selective about this since both of your files have the Tkinter namespace imported.

    You should try and re-factor this code to avoid having to import Tkinter into two modules and having to init mixer in one module and pass it to another.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created the following function to simplify a piece of particularly complex code. CREATE
I created the following interface: <?php interface Action { public function execute(\requests\Request $request, array
On my page, the following function has been created: <SCRIPT language=javascript type=text/javascript> function popModData(
I am trying to do the following: http://msdn.microsoft.com/en-us/library/dd456857.aspx I created the function in the
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have the following function: CREATE FUNCTION [dbo].[ListStockBySubCategory] ( @CategoryID varchar(10), @SubCategoryID varchar(10), @startRowIndex
I am using the following function to create a System.ServiceModel.EndpointAddress when connecting to a
I have the following scalar function in MS SQL 2005: CREATE FUNCTION [dbo].[Distance] (
I have the following function that takes a number like 5 and creates a
I have a strange one. Create a new form. Then add the following function

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.