0

i am making a project for school about welsh history and legends but can't get the two buttons (English & Cymraeg) To Change Two Labels When I Click Them. Any Help Will Be Appreciated!!

from tkinter import BOTH, Canvas
from tkinter import *

Titlet = 'Welsh History And Legends'
startt = 'Click Here To Start'

master = tk.Tk()
master.title('2020 Coding Challenge - Josh Allan')
master.configure(background = 'black')


def English():
    Titlet = 'Welsh History And Legends'
    startt = 'Click Here To Start'

def Welsh():
    Titlet = 'Hanes A Chwedlau Cymraeg'
    startt = 'Cliciwch Yma I Cychwyn'   

title = tk.Label(master, text = (Titlet), font = 'fixedsys 20 bold', fg = 'white', background = 'black')
title.grid(row = 0, columnspan = 2)
ph = tk.Label(master, bg = 'black')
ph.grid(row=2)
LangE = tk.Button(master, text = 'English', font = 'Verdana 9 bold', fg = 'gray', background = 'black', command = English())
LangE.grid(row = 3, column = 0)
LangC = tk.Button(master, text = 'Cymraeg', font = 'Verdana 9 bold', fg = 'gray', background = 'black', command = Welsh())
LangC.grid(row = 3, column = 1)
ph = tk.Label(master, bg = 'black')
ph.grid(row=4)
press_start = tk.Button(master, text = (startt), font = 'Verdana 9 bold', fg = 'gray', background = 'black')
press_start.grid(row = 5, columnspan = 2)

tk.mainloop()


1
  • Be careful, import * is generally bad practice. Commented Mar 10, 2020 at 22:06

2 Answers 2

1

You do not require the () at the end of your command = function

For example:
instead of

LangE = tk.Button(master, text = 'English', font = 'Verdana 9 bold', fg = 'gray', background = 'black', command = English())

put

LangE = tk.Button(master, text = 'English', font = 'Verdana 9 bold', fg = 'gray', background = 'black', command = English)
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the suggestion, but i've already tried this, the buttons still do nothing unfortunately
Have you packed your buttons?
It Wouldn't let Me But I realise the buttons aren't the problem, its the fact it's not changing the labels
0

You can use global variables and have your functions English and Welsh to configure your label. However, I would prefer using tk.StringVar and textvariable option for your label.

import tkinter as tk


master = tk.Tk()
Titlet = tk.StringVar(master, 'Welsh History And Legends')
master.title('2020 Coding Challenge - Josh Allan')
master.configure(background = 'black')


def English():
    Titlet.set('Welsh History And Legends')

def Welsh():
    Titlet.set('Hanes A Chwedlau Cymraeg')  

title = tk.Label(master, text = (Titlet), 
                 font = 'fixedsys 20 bold', 
                 fg = 'white', 
                 background = 'black',
                 textvariable=Titlet)
title.grid(row = 0, columnspan = 2)
ph = tk.Label(master, bg = 'black')
ph.grid(row=2)
LangE = tk.Button(master, text = 'English', font = 'Verdana 9 bold', 
                  fg = 'gray', background = 'black', command = English)
LangE.grid(row = 3, column = 0)
LangC = tk.Button(master, text = 'Cymraeg', font = 'Verdana 9 bold', 
                  fg = 'gray', background = 'black', command = Welsh)
LangC.grid(row = 3, column = 1)
ph = tk.Label(master, bg = 'black')
ph.grid(row=4)

tk.mainloop()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.