Python Forum
user interface Button not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
user interface Button not working
#1
Hello,

Cant understand why i get this error message. Anyone can give me an explaination?

from tkinter import *

def inverser():
    mot = str(EntreeMot.get())
    inversion = ""

    for carac in mot:
        inversion = carac + inversion
        txtMot.configure(text = str(inversion))

fen1 = Tk()

label1 = Label(fen1, text = "Entrez un mot:")
label1.grid(row = 0, column = 0, sticky = E)

EntreeMot = Entry(fen1)
EntreeMot.grid(row = 0, column = 1)

label2 = Label(fen1, text = "Mot inversé:")
label2.grid(row = 1, column = 0, sticky = E)

txtMot = Label(fen1, text = "")
txtMot.grid(row = 1, column = 1)

bouton = Button(fen1, text = "Inverser", command = inverser)
bouton.grid(row = 2)

fen1.mainloop()
Error:
line 31, in <module> bouton = Button(fen1, text = 'Inverser', command = inverser) NameError: name 'inverser' is not defined
Thank you
Reply
#2
Your code works fine for me.
Reply
#3
Works ok for me. The code you provided is not the code that generated the error (line numbers don't match up). Verify that you are running this code

Why are you doing this?
mot = str(EntreeMot.get())
...
txtMot.configure(text = str(inversion))  # Should not be inside the loop
What is the type of EntreeMot.get()? Do you need to use the str() function? Same question for inversion?
def inverser():
    txtMot.configure(text = EntreeMot.get()[::-1])
Frankduc likes this post
Reply
#4
You are right it is working!
I dont like Pycharm its not user friendly. I got to admit i just started using it.

Everytime i open a file and modify it, instead it runs the main.py which seems to be the older version of the file.
I created a new project and now its working.

Thanks!
Reply
#5
(Feb-16-2022, 02:33 PM)deanhystad Wrote: Works ok for me. The code you provided is not the code that generated the error (line numbers don't match up). Verify that you are running this code

Why are you doing this?
mot = str(EntreeMot.get())
...
txtMot.configure(text = str(inversion))  # Should not be inside the loop
What is the type of EntreeMot.get()? Do you need to use the str() function? Same question for inversion?
def inverser():
    txtMot.configure(text = EntreeMot.get()[::-1])

I removed that part i dont need it: txtMot.configure(text = str(inversion))

the type is a string
its a palindrome code: You put "alla" and it tells you if it is or not a palindrome.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help on the User Interface Afia 1 548 Jul-21-2023, 07:22 PM
Last Post: snippsat
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,499 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 2,292 Feb-20-2021, 04:43 AM
Last Post: bowlofred
  Help with User Interface design code ai_masti 0 1,942 Nov-19-2020, 05:58 PM
Last Post: ai_masti
  User Defined function not working Raj_Kumar 4 3,031 Dec-17-2019, 12:44 PM
Last Post: buran
  os.system("netsh interface set interface 'Wi-Fi' enabled") aniyanetworks 12 10,221 Jan-18-2019, 04:07 AM
Last Post: aniyanetworks

Forum Jump:

User Panel Messages

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