Hi i am new to python and i am trying to create a GUI application which will hold different games aimed for autistic children, from where these games can be played.
I have imported the scripts to the Gui application area as follows

from tkinter import *
from tkinter.messagebox import *
from tkinter import Image
from Tetrisino import *
from colorfill import *
from Simulation import *
import os

On the Gui each game is listed with an image, its name and a play button for each one as follows

#Placing of the fouth Activity game name
img3 = PhotoImage(file=imgdir +'tetris(1).gif')
can.create_image(1, 200, image=img3, anchor=NW)
can.image = img3 # reference to keep image
can.create_text(170, 220, text='Tetrisino Activity Game', fill='blue', font=('Arial',14))
button3 = Button(Gui, text = "Play", anchor = NW)
button3.configure(activebackground = "#33B5E5", fg='red', font=('Arial', 14), relief = RAISED, command = Button3CallBack)
button3_window = can.create_window(320, 200, anchor=NW, window=button3)

My problem is that of when i press the play button the same game is being run for any button pressed. what i am trying to do is to code different callback command functions so that when the button command is used this will open the required game, but unfortunately i am stuck and cannot find a way to code the fucntion, till now the below is the code i came up with and it is giving me an error as follows

def Button3CallBack():#Caling the main function of the Tetrisino game
    #import Tetrisino
   global Tetrisino
   Tetrisino = Tetrisino.main ()

Error given

Exception in Tkinter callback
Traceback (most recent call last):
  File "D:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
    return self.func(*args)
  File "C:\Users\Etienne\Desktop\Python  activity games\test gui prototype\Activity Gui.py", line 16, in Button3CallBack
    Tetrisino = Tetrisino.main ()
NameError: global name 'Tetrisino' is not defined

I am sorry if this is a bit long but i need to try to explain what i am doing and happening. I would appreciate it if anyone could help me out as i am stuck and cannot move on to put all the package toghether and test it out.

I think the first thing to do is avoid the import * expression as much as possible. For example, use

from tkinter import *
from tkinter.messagebox import *
from tkinter import Image
import Tetrisino
import colorfill
import Simulation
import os

Then

def Button3CallBack():#Caling the main function of the Tetrisino game
    Tetrisino.main ()

Also if the different games are programs on their own, you should consider launching them as separate processes.

Hi Gribouillis i would like to thank you for your help as excluding the import* from the initial part of the code and then calling the required main function in the button callback function worked out fine.
In fact as the games are different programs i created different callback functions for each button and then called the equired game in them and it worked out fine.
Thanks again for your help and the code snippets as was stuck and could not move further in my project.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.