Python tkinter online
Run tkinter programs in your browser and use their windows: click the buttons, type in the boxes, draw on the canvas.
What works
Widgets
Label, Button, Entry, Text, Checkbutton, Radiobutton, Listbox, Scale, Spinbox, Canvas, Frame, LabelFrame, Message, OptionMenu, and ttk Combobox, Notebook, Progressbar and Treeview.
Layouts
pack with side, fill and expand, grid with sticky, spans and row and column weights, and place with absolute or relative positions.
Variables and events
StringVar, IntVar, DoubleVar and BooleanVar with trace_add, command callbacks, bind for keys and the mouse, and after() for timers and animation.
Dialogs and menus
messagebox (showinfo, askyesno and the rest), simpledialog.askstring and askinteger, and a menu bar with cascades, check and radio items.
How it runs
Your program runs as written. When it reaches mainloop(), the page draws every window it built, and from then on each click, key or change goes back to your callbacks, which update the window. Timers set with after() keep firing, so games and clocks move.
A question asked inside a button's command, such as messagebox.askyesno or simpledialog.askstring, opens as a dialog under the window and waits for your answer. Anything your program prints appears below it, and an error in a callback is shown there without stopping the window.
The same works in the online editor: run a tkinter program there and its window opens in the output panel.
Frequently asked questions
- Can I really run tkinter online?
- Yes. Python runs in your browser, and tkinter calls build a window on the page instead of on the desktop. Your code stays the same: tk.Tk(), widgets, pack or grid, then mainloop().
- Why do other online compilers say "no display" for tkinter?
- Most run Python on a server, which has no screen to open a window on, so tkinter fails with TclError: no display name. Here the window is drawn by the page itself.
- What does not work yet?
- Images (PhotoImage), colours on parts of a Text, widgets placed on a Canvas with create_window, pop-up menus and choosing files. The page says so under the window when a program uses one of them.
- Why does a loop with update() not animate?
- The window appears when the program has finished running, so a while loop that calls update() shows only its last frame. Move each step into a function and call it with root.after(delay, step), the usual tkinter way to animate.
- Does it work on a phone or a Chromebook?
- Yes, in any modern browser. Nothing is installed, and the window takes taps and the on-screen keyboard like a desktop window takes clicks and typing.
More: Python turtle online · Pygame online · Python programs · Online Python compiler