Search the Community
Showing results for tags 'python3.x'.
-
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() >
-
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, I am looking for a new laptop, that would be replacing my current Dell latitude E6540. I have it configured with i7-4800mq and 16 GB of RAM. I also have a 2,5 inch SSD as the main drive. I am looking to give this laptop to a family member, who at the moment, doesn´t have access to a proper computer, since She has been relying on my desktop, and her phone. I am going to be using the new laptop for office 365, libreoffice etc. Other abitti-compatible programs. (IK, office 365 in´t compatible, I just use that for most of my school work.) And off course, abitti exams. For reference, these workloads were fine until the start of this year on this machine. At that time I was running it with only half of the cores (2c/4t). However, it felt a bit sluggish, so I put all the cores to use. TLDR, i7-4800mq is totally fine for all of these workloads. Also, the JDE and PDE I use (eclipse for java, PyCharm for Python) run just fine on the current machine. I would like to understand however, how well these workloads I just mentioned, would scale, comparing the i7-4800mq to a more modern i5-10210U. From what I could see yesterday, when doing my research, the i5 would be only 10-30% improvement in benchmark scores. Would you consider those benchmarks accurate? Thank you for your imput!
- 2 replies
-
- programming
- python3.x
-
(and 2 more)
Tagged with:
-
Hello everyone, I'm using Python. I'm a translator, I have no background in IT, just hobbies and interest. I happen to have to modify hundreds of files for a job to update a price. I could go the usual way and ctrl+h every single price, one by one. But that would be extremely tedious, time consuming and thus expensive. Each price always starts with "Price=" and the value is followed by a "." so I figured I should be able to code a script in Python or something to do that easily. Turns out, it's not that easy because I want to increment an unknown and changing value in a string. So I've got several problems. - How do I tell the code that it's the unknown in between Price= and . that I want to increment? - How to I turn this part into an integer to be able to increment it? - How do I even print it back in its original location as a string? I know I can add str() and int() to change the type on the go, but since I'm a noob, I don't clearly understand what I'm doing and thus don't really know where I should put this type transformations. Could you help me out? Remember, I'm not a pro. IT. I'm a pro with words and I'm tinkering something from tutorials online so please be kind with me. I figured this out so far by myself. I'm fine if you don't give me the solution on a silver platter, I'm interested in learning and training. Here's my code so far, with snippets copy/pasted from the web. If what r/programmerhumour is true, I'm doing something right by copying. The .txt file I call is a test file which only contains: Price=10. import fileinput txt = "Price=10" x = txt.split(", ") print(x) print("Value Incrementor\n") for line in open("c:/Python/test.txt"): if "Price=" in line and "." in line: # up until there I understand what is happening # here I'm not sure the rstrip is useful. I split at the = sign because my value I want to increment is # always after the = s = line.rstrip().split("=") # this is copied from stackoverflow and I don't know what I'm doing from there for n, i in enumerate(s): if "Price=" in i: ind = i.find("Price=") # here I tried to convert the result back into an int to increment it but I don't know how exactly int(s)[n] = i[:ind] + 3 # this is copied too and I believe it means it appends the . at the end to have Price=10. again? print('.'.join(s)) Thank you for any help or pointers! Edit: From tinkering, I'm thinking maybe what I should do is use split() to have the content in a list. No idea how much you can shove into a list and if it's easy to wield? Then, define an int range and tell my code to go through the list and remove everything that is not inside the integer range. But I'm not sure it's going to work because I could define an integer range but the list would contain strings still. I was trying to convert my list into integer just now but I've got an error telling me "price" cannot be converted. That's why I was thinking maybe I can define a range and have a look through the list and remove everything that is not within range. Am I going the right way? Edit2 - Better description of the task: I have several .txt files which contain some sort of metadata for items. The layout is as such: Item name=name, Item description=description, Price=X. I need to update the price value and change it for every item by -3, but the starting price is always different so I can't just open the file and do a search and replace. Because this is going to be a regular task in the future, I wanted to learn and code a script that would do that for me and return a file ready to go. In the present case, the same file, but with every price value decreased by 3. I'm not only interested in the result, but also in learning. I always have a hard time finding learning projects and this time it came to me on its own. Let me know if this is clear enough.
-
So... I need prank Idea's fast Some info: It's the last 3 days of school and I want to fuck with my teachers, I am a python programmer, I have access to a laptop, an iphone, the standard cables (aux, hdmi, vga, dvi) and a logitech bluetooth aux adapter. Unfortunately I do not have an arduino or raspberry pi. The schools computers are set up in a way where files aren't stored locally and there is only one open account that everyone can access, cmd is locked down tho batch files and exe's (exes must be off usb drive) run there are plenty of network printers as well. Any ideas? Mine include: - Replacing all of the shared account's browser shortcuts with porn or shutdown scripts - playing music to class speakers over bluetooth - printing mass amounts of merry christmas flyers with python
- 9 replies
-
- projectors
- python3.x
-
(and 1 more)
Tagged with:
-
hey guys, I have a python program that need some help with. I have to somehow display a text from either from a txt file or from entry widget whenever the data is saved. any help would be great. from tkinter import *#this function will save the data from tkinter to .txt file.def save_data(): a = open("names.txt", "a") a.write("%s\n" % name.get()) name.delete(0,END)#this will quit the widgetdef quitfunc(): app.destroy() #this section will create GUI widget window containing lable, Entry and buttons here.app = Tk()app.title('Name Library')Label(app, text = "Please Enter Name Here:", fg="blue", height=3).pack()name = Entry(app)name.get()name.pack()Label(app, text="Current Name: ", fg="blue").pack()Button(app, text = "Save", fg="red", command = save_data).pack()Button(app, text ="QUIT", fg="pink" , command=quitfunc).pack()#quitfunctionapp.configure(background="green")app.geometry('300x210+200+100')app.mainloop()
-
Hey! Is there a shorter version of this code in Python. Thanks! check = input("Put in the letter: ") word = "word" if(check == word[0]): print(check) else: print("_") if(check == word[1]): print(check) else: print("_") if(check == word[2]): print(check) else: print("_") if(check == word[3]): print(check) else: print("_")