Wingdings Font Not Shown in Tkinter on Macbook - python

Whenever I run the following snippet (on MacOs 10.13.1 using Python 3.6.1):
import tkinter
window = tkinter.Tk()
open_file = tkinter.Button(window, text="1", font=("Wingdings", 12))
open_file.pack()
Instead of showing the following glyph:
The program shows this:
Is there a way in which I can fix this so that the Wingdings font displays correctly?
(Note: The font shows up fine on Windows 10)

Related

Tkinter button background color is not working in mac os

I am trying to change the bg color of a tkinter button on my mac (catalina) but instead of getting a colored background, it is showing a blank space in the layout.
The button code I used:
OpeningFile = Button(root, width=45, bg="#82CC6C", fg="black", text="OPEN", highlightbackground="#82CC6C", highlightthickness=1, borderwidth=0.2, relief="groove", padx=0, pady=0, command=openfile)
OpeningFile.grid()
Result I am getting:
What I expected:
I tried changing many parameters but it is still giving me the same result,
Can it be fixed or it is a bug in tkinter inside mac only?
(It was working properly in windows)
I got the fix:
Use tkmacosx module for tkinter buttons in mac, use "from tkmacosx import Button", and then change the parameters and use borderless=1 to remove the unnecessary layout.
You can see the result I got after using the module:
I was looking for information on the same issue and it seems to be a limitation with tkinter using the MacOS APIs. Basically MacOS says the button colors can't change so tkinter can't change them.
https://github.com/python/cpython/issues/88409

Python tkinter button font is getting pixelated in bigger sizes

First of all, thank you for trying to help me out. I am currently programming my first GUI with tkinter and i try to create buttons with big fonts, cause i want to create a program for visually impaired people. Sadly I have two problems i can't solve with the internet on my own ..
This is the relevant part of my code: (sorry for the german variables)
import tkinter
from tkinter import *
from tkinter import font
import tkinter.messagebox
class Oberflaeche(tkinter.Frame):
def __init__(self, master=None):
tkinter.Frame.__init__(self, master)
self.pack()
MyFont = font.Font(family='times', size=50)
self.close_window = tkinter.Button(self, font=MyFont, text="Programm \nbeenden", command=self.close_window, bg="white", height = 3, width = 18, bd=3, relief="solid")
self.close_window.pack()
def close_window(self):
root.destroy()
root = tkinter.Tk()
root.title("Prototyp MVP")
root.minsize(width=300, height=300)
root.configure(background='white')
oberflaeche = Oberflaeche(master=root)
oberflaeche.mainloop()
when I try to change the font tkFont.Font is not working. There is the Error:
NameError: name 'tkFont' is not defined
That is the reason I tryed font.Font. But no matter how I change the font family or type, it always looks awful and pixelated....
Picture of the failed Button
I am using python 3.5.5, Ubuntu 16.04 and tk 8.6.8.
I am using Spyder(python 3.6) here is the result;
i.hizliresim.com/6NgZlW.jpg
Maybe because of version?
Actually your program is working succesfully ı did not change any codes ı tried on my pc and the result is perfect(Win10 Spyder(Python 3.6).)
i am also used to Jupyter notebook and i was trying with VS Code everything is working well. I suggest you trying to play around with scaling and let me know is it working for you?
Scaling of Tkinter GUI in 4k (3840*2160) resolution
Results
Jupyter
VS Code

Tkinter isn't working with Pycharm

I was running this code and it is supposed to be creating a window but it doesn't create any window in Pycharm. I am using Pycharm Community edition with Python 3.6. When I am running this code in IDLE, the window is generated.
import tkinter
from datetime import date, datetime
root = tkinter.Tk()
c = tkinter.Canvas(root,width =800, height =768, bg = 'black')
c.pack()
c.create_text(100,50, anchor = 'w', fill = 'orange', \
font = 'Arial 28 bold underline', text = 'My Countdown calendar')
Regular python shell and IDLE supports using tk without a mainloop. This is done by several hooks, installed when a tkapp object is being initialized, which handles Tk events while the shell is waiting for user input. However pycharm does not support this. So inorder to diplay your window using pycharm, you have to call
root.mainloop()
at the end.

Combining Tkinter and win32ui makes Python crash on exit

While building a basic app using the winapi with Python 2.7 (I'm on Windows 8.1), I tried to add a small Tkinter gui to the program. The problem is, whenever I close the app window, Python crashes completely (getting crash messages basically).
I have found reports of this issue in several places, but couldn't find a fix or solution. Here are some sources:
http://sourceforge.net/p/pywin32/bugs/443/#8bde
http://www.gossamer-threads.com/lists/python/python/134956 (this one is from 2002!)
It can be reproduced with as much as these 4 lines:
from Tkinter import Tk
import win32ui
root = Tk()
root.mainloop()
And closing the window after running it.
Does anyone know of a solution for this? Any recommendations for a workaround maybe?
A workaround is to invoke the Tkinter-win32UI app with pythonw. Python doesn't crash.
Tested with Python 3.6.3 on Win 10.
Make a button on the Windows and close your program by this button. Here's my script:
from tkinter import *
import win32ui
win = Tk()
frame = Frame(win)
frame.pack(padx = 10, pady = 10)
b1 = Button(frame, text = "Close", command = win.destroy)
b1.pack()
win.mainloop()

Creating a User Interface Using Tkinter (Python)

I looked through a tutorial on using Tkinter and saw that the following code:
>>> from Tkinter import *
>>> win=Tk()
This should produce a box with the title Tk and nothing else. However, when I try this code out no such box appears. I'm not getting any errors so I suspect it's working as intended. Is it possible that there are additional steps I have to take if I'm on a mac?
from Tkinter import *
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()
This code runs automatically, however, in the guide it suggests that I use $ python hello1.py to run this code, which doesn't work. Any ideas on why this might be?
However, this larger block does not work:
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button = Button(
frame, text="QUIT", fg="red", command=frame.quit
)
self.button.pack(side=LEFT)
self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)
def say_hi(self):
print "hi there, everyone!"
root = Tk()
app = App(root)
root.mainloop()
root.destroy() # optional; see description below
The issue seems to have something to do with mainloop but I'm confused because at the same time that earlier block worked just fine with a root.mainloop() part.
Do you run this code in IDLE?
Try above code in terminal (not in IDLE), then it will work as expected.
So if you want to try and run it in Terminal you should follow the steps below
note- 'I find that running programs is Terminal that involve a tkinter Gui will often crash for me, however it may work for you'
1st - Open Terminal
2nd - Type 'python3.4' then press space bar once
3rd - Open a Finder window
4th - Go to where you saved your python file in the Finder window
5th - Once you have located the file in Finder, drag the file into the Terminal window
6th - Press enter, and enjoy your python program.
another note - 'It sounds like you need a better Python IDE, you should try out PyCharm it is a great Python IDE which you can code and run python programs in including tkinter stuff'
You can download PyCharm here https://www.jetbrains.com/pycharm/

Categories