Skip to content
Advertisement

How can I use python 3 tkinter in Linux?

I tried the following program in Win10, it works But I want to use it in linux mint and it display nothing (it display a window with a button on my win10)

from tkinter import * tk=Tk() btn= Button(tk,text="ttk") btn.pack()

I want it display a window with a button on my linux mint

Advertisement

Answer

You need to invoke Tk’s mainloop. Add tk.mainloop() at the end of your code. Besides that, I suggest you use import tkinter as tk (in which case you would have to rename your variable to something else (suggestion: root is kind of idiomatic)) instead of from tkinter import *, since you don’t know what names that imports. It can replace names you imported earlier, and it makes it very difficult to see where names in your program are supposed to come from.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement