Python Forum
def functions in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
def functions in tkinter
#5
I substituted your photos and ran your script- it only outputs errors so I started to comment out lines. I finally got an gui with removing:
  • #s = s()
  • #self.c()
  • #char.wm_attributes("-transparentcolor", "yellow")
the background image showed but the label got garbage collected.
Think about starting over and here's a couple tips:
You have imported tkinter twice once as a wild card * and as tk use the tk.
so your reference will look like self.canvas= tk.Canvas(...)
keep it simple with one canvas object. You can change it's color or clear it-
self.canvas.delete('all') to clear it
self.canvas.itemconfig(bg='black)
you don't need to create new a canvas.
remove the functions in the init function and create them like your skill function.
when you call a function
Quote:s().place(x=0, y=0, width=460, height=401)
have your function widget place or pack or grid the object
I like to recommend the guizero module to people starting with tkinter the creators have
made it easy and simplified the process to making a gui
you can find the docs here:guizero docs
here's an example of your code converted to guizero use your own paths to images:
from guizero import (Picture,App,PushButton,Text)
def change_background():
    picture_1.hide()
    picture_2.hide()
    app.bg='black'
    txt_1.value='Hello Iowa'
    txt_1.color='white'
def redo_background(event):
    picture_1.show()
    picture_2.show()
    app.bg='white'
    txt_1.value='you pressed a key'
    txt_1.color= 'purple'

app= App(title='my app',height=600,width=600)
btn1= PushButton(app, image='path_to_image',
                 height=100,width=100,align='top',
                 command= change_background)
picture_1= Picture(app, image='path_to_image')
picture_2= Picture(app, image='path_to_image',align='left',
                   height=100,width=100)
txt_1= Text(app, text='Hello World even Iowa', color='green',
                size=16, align='bottom')
app.tk.bind('f', redo_background)

app.display()
    
it's a wrapper of tkinter so you'll be familiar with the function it accepts png and gif files by
default or you can use PIL.
best of luck,
Joe
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,698 Apr-24-2021, 08:57 AM
Last Post: ndc85430
  Help with tkinter gui and functions Omer_ 0 1,548 Sep-22-2020, 11:43 AM
Last Post: Omer_
  [Tkinter] tkinter issue with variables carrying over between functions PengEng 1 1,785 Apr-06-2020, 06:13 PM
Last Post: deanhystad
  Functions with Tkinter Reldaing 2 2,592 Jan-03-2020, 06:57 PM
Last Post: Reldaing
  Functions running before they should be - Python Tkinter logic error jhf2 2 2,171 Nov-23-2019, 03:45 PM
Last Post: jhf2
  Binding functions to Menus in tkinter?? Mocap 1 2,481 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,430 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