Python Forum
def functions in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
def functions in tkinter
#1
I need to do something like this:
from tkinter import *
import tkinter as tk
from PIL import ImageTk, Image
import tkinter.filedialog

class ST:
    def __init__(self, char):
        self.ST = char
        self.F = Frame(char)
        self.F.place(x = 0, y = 0, width=460, height=401)

        #def
        def s():
            self.s = Canvas(self.ST)
            self.s.configure(bd=0, highlightthickness=0)
            self.s.place(x=0, y=0, width=460, height=401)
            self.s.create_image(0, 0, image=self.image, anchor=NW)
            self.s.create_text(220, 80,fill="black",font="Times 20 italic bold", text="Skill")

        s = s()

        def c():
            self.c = Canvas(self.ST)
            self.c.configure(bd=0, highlightthickness=0)
            self.c.place(x=0, y=0, width=460, height=401)
            self.c.create_image(0, 0, image=self.image, anchor=NW)
            self.c.create_text(220, 80,fill="black",font="Times 20 italic bold", text="Anne Bonny")
            self.c.create_text(220, 120,fill="black",font="Times 12 italic bold", text="   20 years old \n Loyal to Portugal")

        #Background
        self.image = PhotoImage(file="D:\\o.gif")
        self.bg = Canvas(self.ST)
        self.bg.place(x=0, y=0, width=460, height=401)
        self.bg.create_image(0, 0, image=self.image, anchor=NW)


        #Character
        self.c()

        self.imgc = ImageTk.PhotoImage(Image.open('D:\\f.png'))
        self.panelc = Label(self.ST, image = self.imgc)
        self.panelc.place(x = 59, y = 55, width=75, height=89)

        self.ST.bind("f", self.skill)
        
    def skill(self, event):
        self.panelc.place_forget()
        self.c.place_forget()
        s().place(x=0, y=0, width=460, height=401)        
        
        
char = Tk()
st = ST(char)
char.geometry("460x401")
char.wm_attributes("-transparentcolor", "yellow")
char.mainloop()
when the f key was pressed it should call def s (), but it's not working, can anyone tell me why?

show
NameError: name 's' is not defined
Reply


Messages In This Thread
def functions in tkinter - by Fureneshi - Dec-13-2019, 08:51 PM
RE: def functions in tkinter - by michael1789 - Dec-13-2019, 08:55 PM
RE: def functions in tkinter - by Fureneshi - Dec-13-2019, 08:59 PM
RE: def functions in tkinter - by michael1789 - Dec-13-2019, 10:45 PM
RE: def functions in tkinter - by joe_momma - Dec-26-2019, 09:05 PM
RE: def functions in tkinter - by woooee - Dec-26-2019, 11:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Redirecting all print statements from all functions inside a class to Tkinter Anan 1 2,660 Apr-24-2021, 08:57 AM
Last Post: ndc85430
  Help with tkinter gui and functions Omer_ 0 1,532 Sep-22-2020, 11:43 AM
Last Post: Omer_
  [Tkinter] tkinter issue with variables carrying over between functions PengEng 1 1,758 Apr-06-2020, 06:13 PM
Last Post: deanhystad
  Functions with Tkinter Reldaing 2 2,575 Jan-03-2020, 06:57 PM
Last Post: Reldaing
  Functions running before they should be - Python Tkinter logic error jhf2 2 2,149 Nov-23-2019, 03:45 PM
Last Post: jhf2
  Binding functions to Menus in tkinter?? Mocap 1 2,474 Jul-23-2019, 01:37 AM
Last Post: Larz60+
  Variable not sharing same value between two different functions Python 2.7 Tkinter albert 0 2,413 Aug-31-2018, 10:45 AM
Last Post: albert

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020