Search the Community
Showing results for tags 'tkinter'.
-
I have created Frame with Entry widget to ask user to input his Username and select a team, that he want to join in and also I have created an OpenMenu Widget with 4 teams that user can join. I want to know, how to assign list to OpenMenu variations as a list. For example: Selection "Team 1" = "team1Members" etc. Also I want to know, how to assign data from Entry Widget to appropriate list. For example, if user have selected "Team 1", his username will append to "team1Members" list. My code: < from tkinter import * import tkinter.ttk as ttk team1Members = [] team2Members = [] team3Members = [] team4Members = [] class CollegeApp(Tk): def __init__(self): Tk.__init__(self) container = ttk.Frame(self) container.pack(side="top", fill="both", expand=True) self.frames = {} for F in (StartPage, selectionPage, TeamsPage): frame = F(container, self) self.frames[F] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame(StartPage) def show_frame(self, cont): frame = self.frames[cont] frame.tkraise() class StartPage(ttk.Frame): def __init__(self, parent, controller): self.controller = controller ttk.Frame.__init__(self, parent) self.startMenu() def startMenu(self): heading = Label(self, text="College Tournament Points\n Count Software", font=('Arial', 25)) heading.grid(row=0, column=0, columnspan=2, padx=240, pady=40) start_Btn = Button(self, text="Start", font="Arial 16", width=8, command=lambda: self.controller.show_frame(selectionPage)) start_Btn.grid(row=1, column=0, padx=30, pady=5) exit_Btn = Button(self, text="EXIT", font="Arial 16", width=8, command=self.controller.destroy) exit_Btn.grid(row=1, column=1, padx=30, pady=5) def starting_Program(self): pass class selectionPage(ttk.Frame): def __init__(self, parent, controller): self.controller = controller ttk.Frame.__init__(self, parent) self.teamSelect() def teamSelect(self): heading = Label(self, text="Become a member of a Team", font=('Arial', 25)) heading.grid(row=0, column=0, columnspan=2, padx=200, pady=40) teams = Button(self, text="Teams", font="Arial 24", width=15, command=lambda: self.controller.show_frame(TeamsPage)) teams.grid(row=1, column=0, padx=270, pady=5) class TeamsPage(ttk.Frame): def __init__(self, parent, controller): self.controller = controller ttk.Frame.__init__(self, parent) self.userEntry() def userEntry(self): headingTest = Label(self, text="Enter your Username:", font="Arial 20") headingTest.grid(row=0, column=0, pady=0) usernameEnter = Entry(self, width=40) usernameEnter.grid(row=0, column=1, padx=2, pady=10) UserName = StringVar(self) UserName.set("Team1") AdditionalText = Label(self, text="Please select a team:", font="Arial 18") AdditionalText.grid(row=1, column=0, sticky=W, pady=15) teamSelection = OptionMenu(self, UserName, "Team1", "Team2", "Team3", "Team 4") # How to link those variations to team list? For example: Team 1 = team1Members? teamSelection.grid(row=1, column=1, sticky=W) confirmBtn = Button(self, text="Submit", font="Arial 16", command=()) # Command to Save username in teamXMembers list. Depends on the user selection confirmBtn.config(height=4, width=12) confirmBtn.grid(row=2, column=2, sticky=E, padx=65, pady=300) if __name__ == '__main__': app = CollegeApp() app.geometry("800x500") app.title('Points Counter') app.mainloop() >
-
There is Entry variable in the Tkinter program named "income". We have to convert the str into int for using it in calculations. When gincome=int(income.get()) is used the error is "ValueError: invalid literal for int() with base 10" Please explain the error or the problem in logic. Cheers hV2sq.py
-
I just can't figure out how to create an option menu (drop-down list or combobox) with items from the set in the dictionary. I have various sets, but I'm only interested in the "Individuals" set at the moment. The instructions that I found on the Internet tell how to create an option menu with already existing items in the list or set, but my set is initially empty, and gradually fills up when the user enters a new name in this set. I would like to know how to create an option menu that will display all the names that are in the "Individuals" set. The final result should look like: Please select an individual: Name1 ________________________ Name2 ________________________ Name3 etc. My current option menu just displays all the sets that are in the dictionary, and not the names in the "Individuals" Set. My code: from tkinter import * from tkinter import messagebox import tkinter.ttk as ttk # This code is a simplified version of a full program code. In the original program, there is not only a list # of individuals, but also lists of team1, team2 ... team4. # However, now I am only interested in the problems associated with individual list, # and I cut out all the part of the code related to team. class CollegeApp(Tk): def __init__(self): Tk.__init__(self) container = ttk.Frame(self) container.pack(side="top", fill="both", expand=True) self.frames = {} for F in (IndividPage, listCheckPage, counterPage): frame = F(container, self) self.frames[F] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame(IndividPage) self.lift() def show_frame(self, cont): frame = self.frames[cont] frame.tkraise() # In this class I have created a window with entry widget to input name of individual and save it in # eponymous set "Individual" class IndividPage(ttk.Frame): def __init__(self, parent, controller): self.controller = controller ttk.Frame.__init__(self, parent) self.userEntry() def userEntry(self): headingTest = Label(self, text="Enter your User Name:", font="Arial 20") headingTest.grid(row=0, column=0, pady=5, padx=5) self.usernameEnter = Entry(self, width=40) self.usernameEnter.grid(row=0, column=1, padx=5, pady=5) self.TeamName = StringVar(self) self.TeamName.set("Individual") confirmBtn = Button(self, text="Confirm User", font="Arial 16", command=self.confirm) confirmBtn.config(height=4, width=12) confirmBtn.grid(row=2, column=2, sticky=E, padx=45, pady=360) # Checking the "add_to_team" function has been executed and moving to the next page. def confirm(self): if self.add_to_team(): self.controller.show_frame(listCheckPage) # Function to check the presence of input def add_to_team(self): user = self.usernameEnter.get() if len(user) == 0: messagebox.showwarning(title='No user', message='Please enter a username!') return if self.usernameEnter.get(): self.controller.show_frame(listCheckPage) team_name = self.TeamName.get() team = teams[team_name] team.add(user) self.controller.frames[listCheckPage].team_listboxes[team_name].insert(END, user) print(teams) # Class that creates page with lists of four teams and individuals (Focusing on individuals right now) # Also there is two buttons "Add User" and "Start Counter" to start points calculator class listCheckPage(ttk.Frame): def __init__(self, parent, controller): self.controller = controller ttk.Frame.__init__(self, parent) self.userEntry() def userEntry(self): self.team_listboxes = {} for col_num, teamname in enumerate(teams): teamMembers = Listbox(self) teamMembers.config(height=13, width=15) teamMembers.grid(row=0, column=col_num, padx=5, pady=50, sticky=S) for i, user in enumerate(teams[teamname]): teamMembers.insert(i, user) self.team_listboxes[teamname] = teamMembers INDHeading = Label(self, text="Individuals", font="Arial 16") INDHeading.grid(row=0, column=4, pady=0, padx=15, sticky=N) addUserBtn = Button(self, text="Add User", font="Arial 16", command=lambda: self.controller.show_frame(IndividPage)) addUserBtn.config(height=3, width=80) addUserBtn.grid(row=1, column=0, columnspan=5, pady=0, sticky=N) CounterBtn = Button(self, text="Start Counter", font="Arial 16", command=lambda: self.controller.show_frame(counterPage)) CounterBtn.config(height=3, width=80) CounterBtn.grid(row=2, column=0, columnspan=5, pady=0, sticky=N) # Main problem start here # This class creating dropdown menu (or combobox) with sets "teamX" and "Individual" but it was unplanned # I want this combobox to show not all possible sets (team1, team2 etc.). # Instead of that I want the combobox will show all the names that were entered in the "Individuals" set. # I would also like to point out that the same process will be used for the sets of team1, team2 etc. class counterPage(ttk.Frame): def __init__(self, parent, controller): self.controller = controller ttk.Frame.__init__(self, parent) self.userEntry() def userEntry(self): indivLabel = Label(self, text="Please select an individual: ", font="Arial 20") indivLabel.grid(row=0, column=0, pady=10, padx=10) IndivName = StringVar(self) IndivName.set(teams['Individual']) indivMenu = OptionMenu(self, IndivName, *teams) indivMenu.grid(row=0, column=1, pady=10, padx=10) backBtn = Button(self, text="BACK", font="Arial 16", height=2, width=6, command=lambda: self.controller.show_frame(IndividPage)) backBtn.grid(row=7, column=0, sticky=W, pady=245, padx=10) if __name__ == '__main__': teams = {} for team in range(1, 5): teams[f'Team{team}'] = set() teams = {'Team1': set(), 'Team2': set(), 'Team3': set(), 'Team4': set(), 'Individual': set()} app = CollegeApp() app.geometry("800x500") app.resizable(False, False) app.title('Points Counter') app.mainloop()
-
Hi there Im making a program, than when run, aside from various other things, it plays a GIF of a loading wheel within a tkinter GUI window However, its not working, and i need help I deleted all the code for playing the gif cos it was making me made, but here's the source code Im trying to get a gif to play when login(loginsucess) is run For now im just using a PIL thing, but im going to remove that and replace with the GIF thing
-
from tkinter import Tk, Label, Button num = 1 class MyFirstGUI: def __init__(self, master): self.master = master master.title("Button Simulator 2019") self.label = Label(master, text="Welcome to Button Simulator!") self.label.pack() self.first_button = Button(master, text="Button", command=self.button) self.first_button.pack() def button(self): num = num + 1 self.new_button = Button(master, text = "Button {}".format(), command = self.button) self.new_button.pack() root = Tk() my_gui = MyFirstGUI(root) root.mainloop() I'm trying to learn TKinter for for my computer programming class and this is my code, I'm trying to make the button "first_button" create another button, and any button created will also be able to create another button. Each button will be labeled Button, Button 2, Button 3, etc. I keep getting errors, can anyone help? Thank you.
-
I am trying to make a Gui for the Raspberry Pi MFRC522 RFID Reader but when I launch following code it does not work the Gui code works fine and the MFRC522 code works only outside of tkinter import Tkinter as tk from Tkinter import * import RPi.GPIO as GPIO import MFRC522 import signal continue_reading = true class FullScreenApp(object): def __init__(self, master, **kwargs): self.master=master pad=3 self._geom='200x200+0+0' master.geometry("{0}x{1}+0+0".format( master.winfo_screenwidth()-pad, master.winfo_screenheight()-pad)) master.bind('<Escape>',self.toggle_geom) def toggle_geom(self,event): geom=self.master.winfo_geometry() print(geom,self._geom) self.master.geometry(self._geom) self._geom=geom # Capture SIGINT for cleanup when the script is aborted def end_read(signal,frame): global continue_reading print "Ctrl+C captured, ending read." continue_reading = False GPIO.cleanup() # Welcome message print "Welcome to the Backend of the RFID reader" print "Press Ctrl-C to stop." root=tk.Tk() app=FullScreenApp(root) T = Text(root, height=13, width=200, font=("Helvetica", 32)) T.pack() T.insert(END, "Scanned Items:\n") b = Button(root, text="CLEAR",command=lambda: T.delete(1.0,END), height=4, width = 200) b.pack() def reading(): # Hook the SIGINT signal.signal(signal.SIGINT, end_read) # Create an object of the class MFRC522 MIFAREReader = MFRC522.MFRC522() # Scan for cards (status, TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL) # If a card is found if status == MIFAREReader.MI_OK: print "Card detected" # Get the UID of the card (status, uid) = MIFAREReader.MFRC522_Anticoll() # If we have the UID, continue if status == MIFAREReader.MI_OK: # Print UID print "Card read UID: " + str(uid[0]) + "," + str(uid[1]) + "," + str(uid[2]) + "," + str(uid[3]) # This is the default key for authentication key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] # Select the scanned tag MIFAREReader.MFRC522_SelectTag(uid) # Authenticate status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 8, key, uid) # Check if authenticated if status == MIFAREReader.MI_OK: MIFAREReader.MFRC522_Read(8) MIFAREReader.MFRC522_StopCrypto1() else: print "Authentication error" root.bind(reading) root.mainloop() I am not getting any error messages but im also not getting an console output when i hold a RFID chip near the reader
-
- python
- python 2.7
- (and 4 more)
-
This summer to get a bit more invested in programming, decided to finally pick up a little project of my own. I usually have all my expenses down on an excel sheet, to make sure I break even at minimum lol Which gave me an idea for my first project of my own. a GUI expanse calculator. Decided to go with Python, mainly because I feel like there is more doing with python than the little time I spent with java, with more time spent figuring out the peculiar syntax, I want this project to be a good practice getting comfortable with using classes, storing files, reading from them to put on, creating a decent UI, all that. Feel free to snap me out of the excel sheet way I am approaching this, and if there is a better way to make this. TLDR The reason I made this post, I am unsure what is considered a proper way to store weekly expenditure, a list? How do I go on storing them permanently, so that the next time I open it, the previous data is still there? What's the proper way of storing them so that I can easily read them again, and put them on a table on the final app. Some pointers would be appreciated, not looking for someone to tell me to do xyz, more like you'll need this and that, look into that and that, play around with them kinda thing. I hope I wasn't too obscure, any help is appreciated.
-
Hola! I'm currently making a Python Tkinter app as a personal project, however I've hit a road block. The program inputs an entry into MySQL query which then spits out the result as a Label. You enter a name and it prints out: "ID name email". So it works great, but I need those values as separate variables. I could just access the data with 3 SQL queries but thats just awful. What I need is some kind of a string function that will use the result variable and create three variables or better, a list with [ID,name,email]. I appreciate all input. I didn't include the source code because it doesn't really matter here. A general solution or a point in the right direction will be more beneficial for me, as I will be able to learn and adapt it for my needs.
-
I'm trying to make a settings menu for my A-Level coursework in Computer Science and one of my aims is to have a themes system and a menu to change it. So far, the theme switching menu works and changes the backgrounds, text colours, button colours etc but the actual drop down menu doesn't change colour according to the theme and it doesn't look very good on the dark theme background. Has anyone got much experience with tkinter and can tell me which config value I need to set to change the colour? (attached are an image of my settings menu with the drop down open and the code for getting colours from json file and creating the option menu) Code: theme import from json: creating optionmenu: json file:
-
I've been working on a simple dice game in python part of a school challenge and am adding a gui. Its not meant to be anything grand, just like minesweeper level, so I'm using tk/tkinter. I hit an odd issue, when I try to open/import an image it works...kinda When the function that creates the window and image is on its on script and is called to as shown here, it works with no issue. but when I call the function in the game code I get the following error The function is called with just rolldisplay() and it finds the icon image with no trouble so I'm not sure what the issue is. I've tried moving the window/image to the main program(instead of using a function) and I tried appending the system path and giving a full path name. Thanks I would list the full code but its something like 300 lines and is still messy since I'm adding the gui to what was a functional text based game.