3

I have a functioning code that will not show text on the buttons unless I click and hold the button. When releasing the button's text becomes blank again. I have tried solving this on other forums and

please note: THERE IS NOTHING WRONG WITH THE CODE ITSELF.

There is some sort of issue with how my laptop is running the code. I've tried reinstalling python3.7 as well as tcl-tk. I really don't know what else to do.

Cœur
  • 37,241
  • 25
  • 195
  • 267
S. Argentina
  • 58
  • 1
  • 7
  • I think tkinter is a bit buggy on Mavericks, is that the version of OSX that you're using? – Bryan Oakley Oct 29 '18 at 19:35
  • 1
    I'm currently using Mojave. It didn't appear to give someone else who installed Mojave any problems, – S. Argentina Oct 29 '18 at 20:00
  • How do you know there is nothing wrong with the code itself? Does it work on other machines? Please provide a [mcve]. We can't diagnose problems on code we cannot see. – Bryan Oakley Oct 29 '18 at 20:04
  • There may not be something wrong with your code however we still cannot test without some example to copy and troubleshoot with. Please provide a simple example of your button. You mentioned you are reinstalling Python3.7 however I know some of the early versions of 3.7 were a bit buggy. have you tried one of the 3.6 installs. Maybe 3.6.2.. – Mike - SMT Oct 29 '18 at 20:04
  • Ok. I got this [code](https://pastebin.com/ULfxeuk0) off the tutorial page for tkinter and everyone I've shown it to says it works for them (It also works on my other windows computer). [Here's](https://imgur.com/a/Q8Ed75i) what it looks like while running. If I click and hold to buttons they show the text until I release. – S. Argentina Oct 29 '18 at 20:11
  • This appears to be a mac issue in general. I found a recent post with the same problem and no answer yet. [button text of tkinter not works in mojave](https://stackoverflow.com/questions/52529403/button-text-of-tkinter-not-works-in-mojave) – Mike - SMT Oct 29 '18 at 20:14
  • 1
    Thanks Mike! According to someone on the other post this is happening specifically to the homebrew installed python3 instead of the one downloaded off of the site. I'll try that. – S. Argentina Oct 29 '18 at 20:49
  • 3
    That fixed it! Reinstalling the newest Python version from their website worked. [Solved] – S. Argentina Oct 29 '18 at 20:54
  • That great. Glad you were able to get a fix. – Mike - SMT Oct 29 '18 at 22:35

3 Answers3

4

Here is solution to add this line from tkinter import ttk.

and than use ttk. everywhere you plain to use Button, Label, Entry, etc.:

ttk.Button(text="Login", width="30", command = login).pack()

Here is code so you can try it.

def main_screen():
  from tkinter import ttk

  global screen
  screen = Tk()

  screen.geometry("500x500")
  screen.title("4rManager")

  Label(text="Login/Register", font=("Calibri", 13)).pack()
  ttk.Label(text="").pack()
  ttk.Button(text="Login").pack()
  ttk.Label(text="").pack()
  ttk.Button(text="Register").pack()

  screen.mainloop()

main_screen()

Hope I helped.

1

The reason for that might be how you installed the python. For some, if you installed from hombrew, it doesn't work.

So, try removing python in hombrew. Download and install it from the actual website.

Khamidjon Khamidov
  • 6,783
  • 6
  • 31
  • 62
0

Updating doesn't work for everyone, I've read several posts of those for whom it didn't, and it didn't for me.

But since resizing the window works, there must be something that the tk instance does when resizing that makes everything appear again.

So you might check what happens there, and use that if your program detects if the OS is Mojave. Obviously this is not production worthy and only a fix for your own local projects or maybe some course project, but at least it's something.

Rick
  • 308
  • 3
  • 8