A simple way to create a toggle button for the Tkinter Python GUI toolkit.

Member Avatar
Member Avatar
+1 forum 8

Shows how to create a basic slide show with the Python Tkinter GUI toolkit.

Member Avatar
Member Avatar
+4 forum 19

This is one small snippet of after event usage. You could express if you find this kind of simple code to be usefull as snippet. Notice also vegaseat's sticky message threads in begining of Python forum in addition to code snippets.

Member Avatar
Member Avatar
+0 forum 4

Hi all, Ive been looking to convert one of my programs to include a GUI, and am having issues with the timing aspects of it. Ive included a mock scenario of what my problem is below: Ive defined my GUI as an object via a class, and am using the buttons to call other methods in the class. These methods used to use the time.sleep() function to wait a certain time before completing a task, and am now using the root.after method instead. However, once the button is pressed and the method with the delay is caused, (delay 10s), the …

Member Avatar
Member Avatar
+0 forum 5

Hi guys, I'm new to Python have get done a lot by searching. Now I try to bind a scroll wheel to canvas, but it doesn't do anything. Will someone look at the code what I do wrong? I tried to keep my snippet clean. Hope It's enough. class Viewer(tk.Toplevel): def __init__(self, master, listBoxValue): tk.Toplevel.__init__(self, master) self.grid_rowconfigure(0, weight=1) self.grid_columnconfigure(0, weight=1) cnv = Canvas(self) cnv.grid(row=0, column=0, sticky='nswe') vScroll = Scrollbar(self, orient=VERTICAL, command=cnv.yview) vScroll.grid(row=0, column=1, sticky='ns') cnv.configure(yscrollcommand=vScroll.set) frm = Frame(cnv) cnv.create_window(0, 0, window=frm, anchor='nw') cnv.bind_all('<MouseWheel>', lambda event: self.on_vertical) #select data from database #loop through rows #Label(frm, image=image) # attach image to frame …

Member Avatar
Member Avatar
+0 forum 1

Hello, it is me once more. I am using Python 2.3, and I must use Zelle's graphics class (and I must agree with many of you. Tkinter is much better). We have been tasked with creating a Graphical Scientific Calculator. In addition to the normal operators, it must contain the following buttons: log - base 10 of display ln - base e of display exp - e to the display power sin - sine of display in radians cos - cosine of display in radians tan - tangent of display in radians sqrt - square root of display 1/x - …

Member Avatar
Member Avatar
+0 forum 25

The Tkinter GUI toolkit comes with a scrolled text widget that is called ScrolledText. To get access to it you have to import it separately. It allows you to display large amounts of text in a small space.

Member Avatar
Member Avatar
+0 forum 2

If you have a long message to display in a large readable font, then this little Tkinter GUI toolkit code might help.

Member Avatar
Member Avatar
+1 forum 10

This simple key logger shows any character/special key when pressed.

Member Avatar
Member Avatar
+3 forum 3

Fair warning - I'm still learning so this might be a very newb like question: What I'm trying to do: I'm trying to import a python file into a Tkinter window and run it when I press a button. Eventually I'd like to display the output of the imported script (yahooKeyStats) into a separate window and then save it to a text file but I am still learning how to do that The current issue: When I import "yahooKeyStats" then convert it to tsx for use within this script the yahooKeyStats module seems to run before the tkinter window is …

Member Avatar
Member Avatar
+0 forum 2

I have no idea how to create a Gui from another Gui using python. What I have so far is simply a basic Gui which you select one of the options from a dropdown menu and create another Gui. Here's what I have so far... import sys from tkinter import * #def m forces = [] def mCalculate(): mtext = mass.get() mtext2 = acceleration.get() mlabel = Label(mGui,text = mtext * mtext2).pack() forces.append(mCalculate) return def mGraph(): messagebox.showinfo(title="Graphs",message="Graph option 1") return def secondGui Tk(): secondGui.title('Second Gui') button = Button(text = 'Graph these points', command = mGraph).pack() def mGraphAction(): mPoints = forces mGui …

Member Avatar
Member Avatar
+0 forum 5

I found that one can use dictionaries to hold Tkinter widget config and display parameters. This then permits one to have these dictionaries elsewhere in the code for easy modification instead of buried within the code for each widget. I particularly like to place these dictionaries toward the top of my Tkinter code for easy access and modification. I no longer have to search through a long display of widget code, and then over to the pertinent parameter to modify what I need. I now just find the pertinent dictionary in the area of focus--congfig. or display--and modify it. "Easy …

Member Avatar
+0 forum 0

This is the updated version of the Tiny Tkinter Calculator. It has more power, since you can type in functions contained in the Python math module then press the equals key. You can then move the result into memory for other calculations. The code is written in OOP class style as an exercise, still simple and hopefully very readable. Again, you are welcome to improve the functionality, but don't turn it into a HUGE calculator.

Member Avatar
Member Avatar
+4 forum 8

I would like the widgets on the window to expand as you expand the window. I know you can do it with the pack method but I'm using the grid method to arange my widgets. Pack Method: label = Label(root, text="Some Text") label.pack(expand=1, fill=BOTH) Grid Method I'm using: self.inventoryLabel = Label(self.root, text="\nInventory") self.inventoryLabel.grid(row=3, column=15, columnspan=15, rowspan=1)

Member Avatar
Member Avatar
+0 forum 1

I needed a calculator and I didn't want to use google since my internet is slow. So I made one! Here it is. Working with it is simple. Use the number and operation keys("c" for clear, "p" for pi, and "s" for sqrt) as well as the return and enter key, for equals, or just use the button gui! Hope you like it! The only thing I would really like to work on is the gui. If some one would help me on that that would be greatly appreciated. I will be adding more operations, fixing the power button, and …

Member Avatar
+0 forum 0

I am implementing the last feature of my Python Checkers Game, which is to require the user to make multiple jumps. For captures, I do the following: 1 Check if the move is valid: 2 self.validatedMove = True (The move that has been made is valid.) 3 self.capture() (Captures the piece given a correct user move) 4 How would I implement multiple jumps? I have tried researching for captures and then calling the capture function until there are no more captures left. But it ends up being stuck in an infinite loop! #when Red piece is not a king and …

Member Avatar
Member Avatar
+0 forum 3

This 'sticky' thread is for working examples of Python GUI code. Note that most wxPython examples have their own thread. Please use comments in your code to help the reader. The example code should be usable as a template, so folks get a feel for the toolkit and can use those examples/templates as a basis for more complex programs. We also welcome code that compares the various GUI toolkits. Again, don't clutter up the sticky with questions. Ask question in the regular forum. A brief history of GUI based Operating Systems migh be in order: The first Graphical User Interface …

Member Avatar
Member Avatar
+9 forum 235

I have a tkinter app that has 2 frames. The frame on the left has a bunch of buttons and the frame on the right has a text widget. I use the create_buttons function below to make the buttons. Is there a way to have the button stay sunken when clicked. Then when I click the next button that one stays sunken? I want to be able to see the last button clicked. def create_buttons(self): ''' Loop that creates a button for each file in lterrors.txt. The buttons uses the client/server name as its title text and a custom action …

Member Avatar
Member Avatar
+0 forum 2

Sometimes it's easier to pick an image from the internet to display in your Python Tkinter GUI toolit program.

Member Avatar
Member Avatar
+1 forum 1

import tkinter from tkinter import ttk top=tkinter.Tk() top.title("Scoreboard") top.configure(background="black") w=ttk.Scrollbar(top,orient='vertical') l1=tkinter.Label(top,height=2,width=67,bd=4,text="Welcome To Cricket World Cup 2015",font=("Purisa",15),fg="white",bg="red",relief="ridge") l1.grid(row=0,column=0,columnspan=67) l2=tkinter.Label(top,height=2,width=25,font=("Purisa",15),text="India",fg="white",bg="red",relief="ridge") l2.grid(row=1,column=0) l3=tkinter.Label(top,height=2,width=15,font=("Purisa",12),text="VS",fg="white",bg="black") l3.grid(row=1,column=1) l4=tkinter.Label(top,height=2,width=25,font=("Purisa",15),text="Australia",fg="white",bg="red",relief="ridge") l4.grid(row=1,column=2) l5=tkinter.Label(top,height=9,width=67,bd=4,font=("Purisa",15),bg="red",relief="ridge") l5.grid(row=3,column=0,columnspan=67) l6=tkinter.Label(top,height=2,width=15,font=("Purisa",12),text="India",fg="white",bg="Black",relief="ridge") l6.grid(row=3,column=0,rowspan=1,sticky="NW") l7=tkinter.Label(top,height=3,width=14,font=("Purisa",20),text="183/2",fg="white",bg="Black",relief="ridge") l7.grid(row=3,column=0) l8=tkinter.Label(top,height=3,width=14,font=("Purisa",20),text="45.1",fg="white",bg="Black",relief="ridge") l8.grid(row=3,column=2) l9=tkinter.Label(top,height=3,width=20,font=("Purisa",12),text="RR = 4.057 ",fg="white",bg="Black",relief="ridge") l9.grid(row=3,column=1,rowspan=1) l10=tkinter.Label(top,height=2,width=15,font=("Purisa",12),text="Toss = Australia",fg="white",bg="Black",relief="ridge") l10.grid(row=3,column=2,rowspan=1,sticky="NE") l11=tkinter.Label(top,height=7,width=67,bd=4,font=("Purisa",15),bg="red",relief="ridge") l11.grid(row=6,column=0,columnspan=67) l12=tkinter.Label(top,height=2,width=13,font=("Purisa",20),text="Player name",fg="white",bg="Black",relief="ridge") l12.grid(row=6,column=0,sticky="NWE") l13=tkinter.Label(top,height=2,width=12,font=("Purisa",20),text="Balls",fg="white",bg="Black",relief="ridge") l13.grid(row=6,column=2,sticky="NEW") l14=tkinter.Label(top,height=2,width=11,font=("Purisa",20),text="Runs",fg="white",bg="Black",relief="ridge") l14.grid(row=6,column=1,sticky="NWE") l15=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="44",fg="white",bg="Black",relief="ridge") l15.grid(row=6,column=2,columnspan=8,sticky="e") l16=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="MS Dhoni",fg="white",bg="Black",relief="ridge") l16.grid(row=6,column=0,sticky="w") l17=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="37",fg="white",bg="Black",relief="ridge") l17.grid(row=6,column=1,rowspan=1) l18=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="Rahane",fg="white",bg="Black",relief="ridge") l18.grid(row=6,column=0,sticky="SW") l19=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="12",fg="white",bg="Black",relief="ridge") l19.grid(row=6,column=1,sticky="S") l20=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="29",fg="white",bg="Black",relief="ridge") l20.grid(row=6,column=2,sticky="ES") l21=tkinter.Label(top,height=8,width=67,bd=4,font=("Purisa",15),bg="red",relief="ridge") l21.grid(row=7,column=0,columnspan=67) l22=tkinter.Label(top,height=2,width=10,font=("Purisa",20),text="Player name",fg="white",bg="Black",relief="ridge") l22.grid(row=7,column=0,sticky="NWE") l23=tkinter.Label(top,height=2,width=11,font=("Purisa",20),text="Bowler Name",fg="white",bg="Black",relief="ridge") l23.grid(row=7,column=1,sticky="NEW") l24=tkinter.Label(top,height=2,width=10,font=("Purisa",20),text="FOW",fg="white",bg="Black",relief="ridge") l24.grid(row=7,column=2,sticky="NEW") l25=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="Kholi",fg="white",bg="Black",relief="ridge") l25.grid(row=7,column=0,sticky="w") l26=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="Starc",fg="white",bg="Black",relief="ridge") l26.grid(row=7,column=1,rowspan=1) l27=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="44/1",fg="white",bg="Black",relief="ridge") l27.grid(row=7,column=2,columnspan=8,sticky="e") l28=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="Rohit",fg="white",bg="Black",relief="ridge") l28.grid(row=7,column=0,sticky="SW") l29=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="Johnson",fg="white",bg="Black",relief="ridge") l29.grid(row=7,column=1,sticky="S") l30=tkinter.Label(top,height=1,width=10,font=("Purisa",14),text="80/2",fg="white",bg="Black",relief="ridge") l30.grid(row=7,column=2,sticky="ES") top.geometry("746x746") top.mainloop()

Member Avatar
Member Avatar
+0 forum 1

Hello, I have this code which is working import Tkinter as tk from Tkinter import * LARGE_FONT= ("Verdana", 12) class ChangePages(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) container.pack() container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} for F in (MainPage, Page01, Page02): frame = F(container, self) self.frames[F] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame(MainPage) def show_frame(self, cont): frame = self.frames[cont] frame.tkraise() #MainPage class MainPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self,parent) button1=Button(self,text='Go To Page 1',fg='blue',font=('Helvetica',26),height=5, width=20,command=lambda: controller.show_frame(Page01)).grid(row=1,column=1) #Page01 class Page01(tk.Frame): def __init__(self, parent, controller): option1 = IntVar() option2 = IntVar() option3 = IntVar() tk.Frame.__init__(self, parent) f = Frame(self) f.pack(side='left') label1=Label(f,text='Select …

Member Avatar
Member Avatar
+0 forum 2

I have a Tkinter GUI that is composed of two widgets, the first is a widget class with an entry field and a button and the second is a scrollable text widget class. I have combined these two widget classes to make a single GUI. Each of these widget classes works correctly as individuals. The text field of the GUI is being used to display the contents of a specific index of a list.I want to be able to enter an index number in the entry field and upon pressing the button the text in the text field is re-configured …

Member Avatar
Member Avatar
+0 forum 8

Hello. I have a Class in my python file. That Class contains some functions. How can i set the command of a Tkinter butten so that call a function of that class? I tried this but it didn't work: class calculating(object): def __inint__(self): self.current = 0 def addition(self, amount): self.current += amount def result(self): return self.current print (self.current) def show(self): lbl["text"] = result() btn1 = Button(root, text = "add", command = calculating.addition) btn1.pack() btn2 = Button(root, text = "result", command = calculating.show) btn2.pack() lbl = Label(root) lbl.pack

Member Avatar
Member Avatar
+0 forum 2

How can i create a drop-down menu in Tkinter?

Member Avatar
Member Avatar
+0 forum 6

Hi everybody. I have problem with .pack() and .grid(). I have to use this line: mywin.pack(fill=BOTH, expand=YES) I have used .grid every where on my file but now here i have copied a pice of code from some where and have pasted to my file, as you see it has used .pack(). I can't change all .grid() to .pack() because it's difficult for me to use .pack() when i want to set for example the place and direction of buttons, so i use .grid() options like row and column. And if i change that line, that .pack() to .grid(), it …

Member Avatar
Member Avatar
+0 forum 3

Hello. When we want to insert a vlue into a table in sqlite, we use this line, right? cursor.execute('INSERT INTO colors Values ("red", "blue")') As we can see above, we want to insert 2 words and we type them as when we are typing whole the codes. But i want to get 2 words from input and insert them into the table in sqlite. I'm using Entry box in Tkinter window and i want something like this: ent = Entry() ent.grid() ################ cursor.execute('INSERT INTO colors VALUES (ent.get())') But it doesn't work and give me a syntaxt error. What can i …

Member Avatar
Member Avatar
+0 forum 17

Hi, is that possible Tkinter to play a video? And if not possible so what GUI programming that you can recomended? I already search in google, find a few but there's dead link.. I need to show 2 windows, first the original video, and the second is video after processing

Member Avatar
Member Avatar
+0 forum 2

Hello. I have used ScrolledText in my code, the scroll bar that appears is attached to the frame and although it scrolls the text box contents, I want that it was attached to the text widget itself. What can i do?

Member Avatar
Member Avatar
+0 forum 3

Hello friends :) I'm almost familiar with Tkinter and Kivy frameworks, but i'm looking for other python GUI frameworks, soething better than Tkinter. Kivy is also great but i need to watch more tutorial videos and i'm not able to do that right now. Can you introduce a better and more easier framework to me? Thank you ;)

Member Avatar
Member Avatar
+0 forum 6

Hello. How can i set an image as a Tkinter window background? I mean the whole background of the window not a photo area.

Member Avatar
Member Avatar
+0 forum 4

The End.