Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TkInter: execute whole script at once problem

Status
Not open for further replies.

DisAstro

Programmer
Oct 22, 2006
7
0
0
NL
Hey!

I'm having serious problems using tkInter. Everything went fine when I was still using the pack method. Now, after I have switched to the grid method, a problem has come up. No matter what I try, the whole script is executed at once. And I don't want that.

The idea is that you select some options in step one, click continue, and step two pops up. No matter what I try, step two immediatly pops up at startup.

Here's my script:

Code:
import random
from Tkinter import *

class Startup:

    def __init__(self, master):

        frame = Frame(master,bg="Gray")
        frame.pack()

        self.root = master
        self.master = master

        self.stepo = Label(frame,text="Step 1.",font=(15),bg="Gray",relief=RAISED,bd=3,fg="Red")
        self.stepo.grid(row=1,column=2)

        self.setuplab = Label(frame,text="Setup players and games",font=(15),relief=GROOVE,bd=1,justify=LEFT,bg="Gray")
        self.setuplab.grid(row=3,column=1)

        self.playslide = Scale(frame, from_=2, to=10, orient=HORIZONTAL,bg="Gray",troughcolor="Gray")
        self.playslide.grid(row=7,column=1)

        self.playlab = Label(frame,text="Players.",bg="Gray")
        self.playlab.grid(row=8,column=1)

        self.egames = Entry(frame)
        self.egames.grid(row=5,column=1)

        self.gamelab = Label(frame,text="Games.",bg="Gray")
        self.gamelab.grid(row=6,column=1)

        self.setuplab = Label(frame,text="Setup profiles select type",font=(15),relief=GROOVE,bd=1,justify=LEFT,bg="Gray")
        self.setuplab.grid(row=3,column=3)

        profpick = 0
        self.rad1 = Radiobutton(frame, text="Randomly", variable=profpick, value=1,bg="Gray",highlightcolor="Gray")
        self.rad1.grid(row=4,column=3)
        self.rad2 = Radiobutton(frame, text="Manual", variable=profpick, value=2,bg="Gray",highlightcolor="Gray")
        self.rad2.grid(row=5,column=3)
        self.rad3 = Radiobutton(frame, text="Standard set", variable=profpick, value=3,bg="Gray",highlightcolor="Gray")
        self.rad3.grid(row=6,column=3)

        self.steptwo = Button(frame,text="Go to step 2",command=self.cont(),bg="Gray")
        self.steptwo.grid(row=10,column=2)

    def cont(self):

        games = self.egames.get()
        players = self.playslide.get()

        app = StepT(root)

class StepT():

    def __init__ (self,master):

        frame = Frame(master,bg="Gray")
        frame.pack()

        self.stepi = Label(frame,text="Step 2.",font=(15),bg="Gray",relief=RAISED,bd=3,fg="Red")
        self.stepi.grid(row=11,column=2)

root = Tk()
app = Startup(root)
app.master.title("Dis Astro's Poker Simulator")
root.mainloop()

What I have tried: pass the profpick int to the cont function, and check if it is not 0. However, no matter what I tried, nothing happened.

I hope somebody can help me!
 
Hi,

try to run you script from command line console.
If you use windows, then click at Start/Run.., type in
cmd
then change to your directory where your script sits and type:

python your_script.py

Then you get such an error
Code:
  File "D:\Analyza\Python\pok.py", line 53
    class StepT():
                ^

This means that you typed by mistake the parentheses (). In the class definition the parentheses are only used, when the class is inherited and then in the parentheses the parrent class is placed

so correct
Code:
class StepT():

by deleting of ()to
Code:
class StepT:
and your script will be running.
 
Thanks for that, but it doesn't fix my problem. My script still runs in a faulty way. I don't want StepT to execute untill you press the "Go to Step 2" button. However, no matter what I do, StepT is executed immediatly on startup, or not at all. This behaivour remains unchanged, even after fixing the () on StepT.

I really hope someone call help me... ???
 
comand -function will be written without parentheses
so correct
Code:
self.steptwo = 
Button(frame,text="Go to step 2",command=self.cont(),bg="Gray")
to
Code:
self.steptwo = 
Button(frame,text="Go to step2",command=self.cont,bg="Gray")
Is this what you want?
 
That fixed it. Thank you very, very much!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top