7 Replies - 1954 Views - Last Post: 03 June 2012 - 11:01 AM Rate Topic: -----

#1 rosepetalpowder  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 65
  • Joined: 28-February 12

problem tkinter gui - slot machine assignment

Posted 02 June 2012 - 10:23 AM

My prof has asked us to do slot machine code using python tkinter.

so got 3 slots (self.label1, self.label2,self.label3) which needs to take images. when i press button spin, it should shuffle images, do calculations. what am i doing wrong. what should be my next move.

def Button2Click(self):
        global imageList
        imageList =[self.myimage1,self.myimage2,self.myimage3,self.myimage4,self.myimage5,self.myimage6,self.myimage7,self.myimage8]
        list = imageList[random.randint(0,7)]
        #outcome = [0,0]
        #list2=imageList[random.randint(7,0)]
        self.Label2.configure(image=list)
        self.Label3.configure(image=list)
        self.Label4.configure(image=list)

This post has been edited by rosepetalpowder: 02 June 2012 - 10:32 AM


Is This A Good Question/Topic? 0
  • +

Replies To: problem tkinter gui - slot machine assignment

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5572
  • View blog
  • Posts: 11,913
  • Joined: 02-June 10

Re: problem tkinter gui - slot machine assignment

Posted 02 June 2012 - 01:21 PM

Quote

what am i doing wrong.

Well... What's your error? What's going wrong? You haven't described a bug so before anyone can help you they need to understand the problem.
Was This Post Helpful? 0
  • +
  • -

#3 rosepetalpowder  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 65
  • Joined: 28-February 12

Re: problem tkinter gui - slot machine assignment

Posted 02 June 2012 - 03:45 PM

View PosttlhIn`toq, on 02 June 2012 - 01:21 PM, said:

Quote

what am i doing wrong.

Well... What's your error? What's going wrong? You haven't described a bug so before anyone can help you they need to understand the problem.



The above code just changes the images in all the three slots. it shows the same image on all three everytime i click on the spin button. and I have a bet textbox, jacpot text box. player money text box. output text box.

I need to do calculations when player puts in money in the bet box. jacpot and player text box is greyed out and has a default 500 and 1000.

I need to shuffle the images in all the three images. different image shud load in different label. shudnt the random.randint - take care of this? is there a different command i use?

then how do i program calculations with information in the text boxes?
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5572
  • View blog
  • Posts: 11,913
  • Joined: 02-June 10

Re: problem tkinter gui - slot machine assignment

Posted 02 June 2012 - 04:13 PM

Quote

it shows the same image on all three everytime i click on the spin button

Line 4 - you set list to a randomly chosen image (an element from the array with a randomly chosen index, to be specific). And since list isn't really a list of anything you might consider giving it a better name, like randomImage that better describes what it really is. Proper naming does wonders for making your code manageable.
line 7,8,9 - you set the controls to the same instance of list without randomly selecting a new value. That would get you the same value for all three controls.

Quote

I need to do calculations when player puts in money in the bet box. jacpot and player text box is greyed out and has a default 500 and 1000.

Yes: You do need to do this. But as I see it, you haven't even tried. There isn't a single line of code where you've made an effort. Open your textbook and re-read the chapter involving calculations and how to do math in python. Then at least try to write something. If it doesn't work, post the code in this thread rather than starting a new one. But until you actually have some code here to help with, nobody here is going to write it for you.

This post has been edited by tlhIn`toq: 02 June 2012 - 04:16 PM

Was This Post Helpful? 1
  • +
  • -

#5 rosepetalpowder  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 65
  • Joined: 28-February 12

Re: problem tkinter gui - slot machine assignment

Posted 03 June 2012 - 08:52 AM

View PosttlhIn`toq, on 02 June 2012 - 04:13 PM, said:

Quote

it shows the same image on all three everytime i click on the spin button

Line 4 - you set list to a randomly chosen image (an element from the array with a randomly chosen index, to be specific). And since list isn't really a list of anything you might consider giving it a better name, like randomImage that better describes what it really is. Proper naming does wonders for making your code manageable.
line 7,8,9 - you set the controls to the same instance of list without randomly selecting a new value. That would get you the same value for all three controls.

Quote

I need to do calculations when player puts in money in the bet box. jackpot and player text box is greyed out and has a default 500 and 1000.

Yes: You do need to do this. But as I see it, you haven't even tried. There isn't a single line of code where you've made an effort. Open your textbook and re-read the chapter involving calculations and how to do math in python. Then at least try to write something. If it doesn't work, post the code in this thread rather than starting a new one. But until you actually have some code here to help with, nobody here is going to write it for you.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.

Hey your suggestion for images worked. Thank you.

Now for the calculations.

I did try calculations for regular text based slot game.(given below). But now for GUI I have three text boxes. one text box - jackpot, one text box - money, one text box user input bet. How do I do calculations with info from text boxes. I dont want u to write code for me. Point me in the right direction.

 def pullthehandle(Bet, Player_Money, Jack_Pot):
    """ This function takes the Player's Bet, Player's Money and Current JackPot as inputs.
        It then calls the Reels function which generates the random Bet Line results.
        It calculates if the player wins or loses the spin.
        It returns the Player's Money and the Current Jackpot to the main function """
    Player_Money -= Bet
    Jack_Pot += (int(Bet*.15)) # 15% of the player's bet goes to the jackpot
    win = False
    Fruit_Reel = Reels()
    Fruits = Fruit_Reel[0] + " - " + Fruit_Reel[1] + " - " + Fruit_Reel[2]
    
    # Match 3
    if Fruit_Reel.count("Grapes") == 3:
        winnings,win = Bet*20,True
    elif Fruit_Reel.count("Banana") == 3:
        winnings,win = Bet*30,True
    elif Fruit_Reel.count("Orange") == 3:
        winnings,win = Bet*40,True
    elif Fruit_Reel.count("Cherry") == 3:
        winnings,win = Bet*100,True
    elif Fruit_Reel.count("Bar") == 3:
        winnings,win = Bet*200,True
    elif Fruit_Reel.count("Bell") == 3:
        winnings,win = Bet*300,True
    elif Fruit_Reel.count("Seven") == 3:
        print("Lucky Seven!!!")
        winnings,win = Bet*1000,True   

Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5572
  • View blog
  • Posts: 11,913
  • Joined: 02-June 10

Re: problem tkinter gui - slot machine assignment

Posted 03 June 2012 - 09:17 AM

What does that logic really say?

If 3 reels all show the grapes, then the winnings is the bet * 20
If 3 reels all show the Banana, then the winnings is the bet * 30
If 3 reels all show the Orange, then the wiings is the bet * 40
...

So you need a method that counts number of occurances of the parameter provided.

13 if Fruit_Reel.count("Grapes")

the method Fruit_Reel.count() takes a parameter then looks for that fruit. It returns the number of those fruit. That's how this is comparing to 3

13 if Fruit_Reel.count("Grapes") == 3:

Read aloud this says:
if.. the returned value of Fruit_Real.count(of Grapes)... is equal to 3

It makes more sense if you read it aloud in plain English, right?

So make a method that does pretty much that same thing: That counts the number of occurrences of the specified fruit picture.
Was This Post Helpful? 0
  • +
  • -

#7 rosepetalpowder  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 65
  • Joined: 28-February 12

Re: problem tkinter gui - slot machine assignment

Posted 03 June 2012 - 09:51 AM

View PosttlhIn`toq, on 03 June 2012 - 09:17 AM, said:

What does that logic really say?

If 3 reels all show the grapes, then the winnings is the bet * 20
If 3 reels all show the Banana, then the winnings is the bet * 30
If 3 reels all show the Orange, then the wiings is the bet * 40
...

So you need a method that counts number of occurances of the parameter provided.

13 if Fruit_Reel.count("Grapes")

the method Fruit_Reel.count() takes a parameter then looks for that fruit. It returns the number of those fruit. That's how this is comparing to 3

13 if Fruit_Reel.count("Grapes") == 3:

Read aloud this says:
if.. the returned value of Fruit_Real.count(of Grapes)... is equal to 3

It makes more sense if you read it aloud in plain English, right?

So make a method that does pretty much that same thing: That counts the number of occurrences of the specified fruit picture.


u just explained my code back to me. I am aware I need to do it with pictures. my question was the integer values from textboxes how to retrieve them and do calculations and put it back.
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5572
  • View blog
  • Posts: 11,913
  • Joined: 02-June 10

Re: problem tkinter gui - slot machine assignment

Posted 03 June 2012 - 11:01 AM

my question was the integer values from textboxes

Why would you get an integer back from a textbox that contains an Image?

You need to check if the IMAGE in the textbox is that of the Grape, the Orange, the Apple etc.

You're the only person that knows if self.myimage1 is a grape or kumquat

So you need to equate 'grape' to imageList[3] for example.
Then check if each textbox contains imageList[3]
something to the logic of
countOfFruitVariable += textbox1.Image equals FruitParameterPassedIn

I'll help you with the logic. I'm not writting it for you.

This is homework. We aren't going to write the code. We will help with the code you write. But so far you haven't written code that even tries to retrieve this image or check it: You've only shown code for a vaguely similar application that works in a text basis not a GUI basis.

If the logic isn't enough, then you lack a grasp on the material of this chapter. Re-read your textbook. Talk to your instructor.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1