Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
button coding help
#1
Hello,
I am trying to learn how to code in python, and I found an amazing website called code club. However I have encountered a problem which is that it doesn't tell me how to get the program to understand where the mouse is and update various thing depending on where the mouse is, and weather it has clicked or not. basically I want to know how to program a button. I surched this up online and found that you need to import tinkerer, or something like that. So I copy and pasted some code into a trinket project (everything I have done in trinket has worked by the way) but it said that you couldn't import tinkerer for some reason.

I don't really know what to do, and would really appreciate it if someone could help me.
what I though might work though, is using if statements of say "if the mouse here then do this, else do nothing" but I don't know how to phase that nor weather it is even possible. so please help me if you know what the problem is. :)
Reply
#2
Do you mean tkinter? Tkinter is a GUI framework for python. You dont really have to do much work in tkinter to create a button.
import tkinter as tk

root = tk.Tk()

def callback():
    print('click')

btn = tk.Button(root, text='OK', command=callback)
btn.pack()

tk.mainloop()
Recommended Tutorials:
Reply
#3
Hi,

Quote:I am trying to learn how to code in python
As you are trying to learn and seem to be at the beginning, but at the same time talk about GUIs and stuff, I have to say you are three steps too far.

To use any of the GUI frameworks, you need an understanding of Python's object orientation, classes and their methods. Without you cannot make it work and won't be able to understand what you are doing.

So learn the basics first (e.g. by working yourself through the official Python tutorial at docs.python.org) and than go further.

Regards, noisefloor
Reply


Forum Jump:

User Panel Messages

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