Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] Help with tkinter; images and button commands
I'm making a game and I have a few problems. The first is that the BG image shows up when the game is opened. I really just want it to open when the button is clicked. The second problem is the button is not triggering the command when it is pressed. It is supposed to delete everything and pull up button of the characters.
Here's the code
from tkinter import *

tk = Tk()
ShotonButton = Button()
Shoton = Button()
Something = Button()
startbtn = Button()
CharacterVariable = 0
CharacterVariable2 = 0

ShotonImage = PhotoImage(file='C:/Users/Chadd/Pictures/Converted/Converted/Official Shoton.gif')
SomethingImage = PhotoImage(file='C:/Users/Chadd/Pictures/Converted/Character 1.gif')
BGImage = PhotoImage(file='C:/Users/Chadd/Downloads/Background.gif')

class Sprites():
    def Shoton():
        ShotonButton = Button(tk, text="", command=CharacterSelection(1), bg='red')
        Shoton = ShotonButton
        Shoton.config(image=ShotonImage, width=130, height=200 ), rely=.1)
        ShotonLabel = canvas.create_text(145, 310, text='Shoton', fill='red', font=('Times', 30))
    def Poop():
        Something = Button(tk, text="", command=CharacterSelection(2), bg='Brown')
        sg = Something
        sg.config(image=SomethingImage, width=130, height=200), rely=.1)
        sgLabel = canvas.create_text(310, 310, text='PoopHead', fill='Brown', font=('Times', 25))

class Fighter():

class GameCanvas():
    def BackGround():
        canvas.create_image(0, 0, anchor=NW, image=BGImage)
    def CharSelInter():

#Character Selection
class Char():
    def CharSel(character):
        CharacterVariable = character
        findCharacter(0, character)

    def CharSel2(character):
        Char.findChar(1, character)
        CharacterVariable2 = character

    def findChar(value, char):
        if value == 1:

#Start Screen
canvas = Canvas(tk, width=800, height=800, bg='blue')

startbtn = Button(tk, text="Start Game", command=GameCanvas.CharSelInter(), font=('Times', 50), bg='red', foreground='blue')
startbtn.pack(), rely=.8, anchor="c")

GunnerText = canvas.create_text(400, 300, text='The Gunner', fill='red', font=('Times', 100))
Thanks in Advance
Age Doesn't Matter, Your Passion Does
- Shreya Jain
Command bindings should not call the event handler function/method ie take the () off the end, otherwise they are called imediately and the result of the call is bound to the event.
In addition, use partial to send args to a function
from functools import partial
## there is no function CharacterSelection in the code you posted
ShotonButton = Button(tk, text="", command=partial(CharacterSelection, 1), bg='red')
when you have time, peruse the Python Style Guide, function names are all_lower_case_with_underscores.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Problem with Submit button Tkinter Reldaing 2 130 Jan-05-2020, 01:58 AM
Last Post: balenaucigasa
  tkinter button not accessing the command when clicked jhf2 1 189 Nov-23-2019, 10:17 PM
Last Post: DT2000
  Tkinter button in for Simpsunt 3 157 Nov-23-2019, 01:41 AM
Last Post: Larz60+
  tkInter and Pillow don't display any images in GUIs - program gives errors instead SomeRandomGuy 9 580 Oct-29-2019, 02:57 PM
Last Post: SomeRandomGuy
  [Tkinter] Checking button click in Tkinter GalaxyCoyote 3 335 Oct-20-2019, 03:28 AM
Last Post: GalaxyCoyote
  [Tkinter] Tkinter button help and general commands Iceman 1 310 Sep-01-2019, 05:09 PM
Last Post: Yoriz
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 515 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [Tkinter] Tkinter window pop up again when i click button Orimura_Sandy 1 755 May-12-2019, 08:17 PM
Last Post: joe_momma
  tkinter- adding a new window after clicking a button built on the gui ShashankDS 2 1,529 Apr-18-2019, 12:48 PM
Last Post: ShashankDS
  Tkinter Button Settings kaanertugrul 3 1,324 Jan-25-2019, 03:41 PM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)