Search code examples
pythonpython-3.xtkinterttkpython-3.6

How to import Gtk, gi.repository? Best GUI for table grids? Tkinter * vs ttk?


I found a program, that uses gi, gi.repository, and Gtk. It seems like a great GUI for my Python script that involves Excel sheet imports and table grids.

I am finally able to import gi after much work, but still not able to import gi.repository or Gtk (No module named "")even though I believe I have them installed correctly.

I tried installing all the Gnome stuff and used the Jhbuild for GTK3 which only screwed all my files up. I uninstalled and reinstalled this stuff like 5 times. I also had to delete and reinstall Python.

I gave up on Jhbuild. Isn't there a simpler way to install GTK? Or is there a better GUI?

I have been using tkinter in Python 3, but the only problem is that a script I found that incorporates a table grid uses ttk while I do not use ttk. I do not understand ttk and excessively definitive (i.e. tkinter.ttk.Label, etc vs tkinter *'s Label). Ttk seems obsolete; please correct me if I am wrong.

For my simple beginner scripts I have been using from tkinter import *, which one would think that importing all (*), would include ttk, but I guess it must be specified. Using ttk messes up everything in my script even when I translate everything from tkinter * to ttk. I am clearly doing something wrong or ttk is obsolete. I receive errors such as unexpected arguments, things are not defined, name errors, __init__ errors, etc. It seems you cannot mesh (newer?) tkinter * modules with (older?) ttk modules.

Again, if anyone knows the best, newest and simplest GUI, I would really appreciate it. I using Python 3 on a Mac (Sierra 10.12.3).


Solution

  • Every time tkinter is imported(any way or form), it will search your computer for ttk, which is a requirement for tkinter. On Mac Sierra, the default ttk doesn't work and it's very buggy so you will need to install a custom ttk.

    Follow this link to install the recommended version for mac. REMEMBER TO ONLY INSTALL 8.5 not 8.6 python doesn't support 8.6 yet.

    Other common GUIs include pyqt and pygame(for games), while built in turtle for drawing. As a side note, I prefer using tkinter since it's easy to use and have most of the functionalities.

    importing tkinter like this from tkinter import * isn't the preferred way, since name spaces is a tricky thing, since it's pretty easy to accidentally override something. For example: naming a tkinter.label Label. And the next time you wonder why you can't create a another label. So a better way would be import tkinter as tk.