I have been doing some work in python and have came across Tkinter which is very useful for my project. I was in the process of making a screen where there is a button and a text entry box however when the text entry box is present, no button shows up. However when I remove the entry box, I can see the button.
Here is the part of the script I've been working on:
Hi, I have been doing some work in python and have came across Tkinter which is very useful for my project. I was in the process of making a screen where there is a button and a text entry box however when the text entry box is present, no button shows up. However when I remove the entry box, I can see the button.
from tkinter import *
def submit1():
print("working");
def password1():
passwordbox= Tk()
passwordbox.title("Password Verification")
passwordbox.configure(background="white")
passwordbox.geometry("1000x1000")
box1 = Entry(passwordbox, width=200, bg="gray")
box1.grid(row=2000, column=10, sticky=W)
submit = Button(passwordbox, text="Submit", width=20, height=5,
bg="black", fg="white", command=submit1)
submit.grid(row=1000, column=15, sticky=W);
password1()
The text box should show to entry box and the button however it only shows the button
If the entry box code was # out, the button will work
Anyone got any ideas?
You need to add a line passwordbox.mainloop() at the end of password1 definition. Also you need to specify row and column of the grid properly.
Set Entry box to row 0 and column 0
Set Submit button to row 1 and column 0
from tkinter import *
def submit1():
print("working");
def password1():
passwordbox= Tk()
passwordbox.title("Password Verification")
passwordbox.configure(background="white")
passwordbox.geometry("1000x1000")
box1 = Entry(passwordbox, width=200, bg="gray")
box1.grid(row=0, column=0, sticky=W)
submit = Button(passwordbox, text="Submit", width=20, height=5,
bg="black", fg="white", command=submit1)
submit.grid(row=1, column=0, sticky=W);
passwordbox.mainloop()
password1()
Related
I have created a menu bar on the parent window. And I have made a child window as userguide.py which is assigned to one of the button on the menu that is "USER GUIDE". When I click on the button the child window opens, but when again clicked it opens one more window and so continues if clicked on the menu button. How do I disable the menu button until the child window is closed. I am sharing the code below.
Below this is code of the menu in parent window
from tkinter import *
from tkinter import ttk
from userguide import userGuide
root = Tk()
root.title("GhostTube - by RuSher")
root.iconbitmap(r"C:\Users\ayush\Desktop\BOTRAW\main\ghost.ico")
root.maxsize(400, 685)
root.minsize(400, 685)
root.geometry("400x685")
style = ttk.Style()
style.theme_use("clam")
menubar = Menu(root)
menubar.add_command(label="USER GUIDE I", command=userGuide)
menubar.add_command(label="ABOUT I")
menubar.add_command(label="CONTACT", command=contactInfo)
root.config(menu=menubar)
root.mainloop()`
Menu bar image
Below given code is the child window code i.e. userguide.py
from tkinter import *
from tkinter import ttk
def userGuide():
master = Tk()
master.title("GhostTube - by RuSher")
master.iconbitmap(r"C:\Users\ayush\Desktop\BOTRAW\main\ghost.ico")
master.maxsize(400, 685)
master.minsize(400, 685)
master.geometry("400x685")
style = ttk.Style()
style.theme_use("clam")
userLabel = Label(master, text=" HOW TO USE ", bg="black", fg="white", font=("Elephant", 18))
userLabel.grid(pady=10)
guide1Frame = LabelFrame(master, text="STEP 1 :", padx=5, pady=10)
guide1Frame.grid(row=1, column=0, padx=5)
step1label = Label(guide1Frame, text="First step is to add accounts to the bot, for that click on \n“Load Accounts” then locate the “YT accounts.txt” file and select it.\nIt will load all the accounts in the file.")
step1label.grid()
guide2Frame = LabelFrame(master, text="STEP 2 :", padx=5, pady=10)
guide2Frame.grid(row=2, column=0, padx=5)
step2label = Label(guide2Frame, text="Add the video URL of which you want to boost. Type or copy paste \nyour video URL on (Type Here) space and click on “Add”. \nOr you can make a text file of your video URLs and load it \nby clicking on “Load Video URLs” and selecting the text file.")
step2label.grid()
guide3Frame = LabelFrame(master, text="STEP 3 :", padx=5, pady=10)
guide3Frame.grid(row=3, column=0, padx=5)
step3label = Label(guide3Frame, text="Now you need to select the action you want to have \non the video to be performed, that are: LIKE, DISLIKE, \nSUBSCRIBE, UNSUBSCRIBE or COMMENT. You can select multiple \nactions at a time. After completing this Click on “START” button.")
step3label.grid()
guide4Frame = LabelFrame(master, text="STEP 4 :", padx=5, pady=10)
guide4Frame.grid(row=4, column=0, padx=5)
step4label = Label(guide4Frame, text="For Comments, You can Type or copy paste comments on\n(Type Here) of your choice, one comment at a time then click\non “Add” button and then type next comment of your choice then\nclick on “Add” and repeat if you want more. Or you can make\na text file of comments of your choice (one comment per line)\nand load it by clicking on “Load Comments”and locate your\ncomments text file and select it. Then click on “START”.")
step4label.grid()
guide5Frame = LabelFrame(master, text="STEP 5 :", padx=5, pady=10)
guide5Frame.grid(row=5, column=0, padx=5)
step5label = Label(guide5Frame, text="When the bot runs first time it can take time because of it prepares\nthe system, after the process starts please do not intercept it.\nLet it complete all the actions. The process goes in steps; \nfirst, a CMD interface will open then a Firefox window will start and\nit will complete one action then the Firefox window will close and\nthe same steps will repeat according to the actions to be taken.")
step5label.grid()
quote = Frame(master, padx=5, pady=10)
quote.grid(row=6, columnspan=2)
enjoy = Label(quote, text="Experience The Best", font=("Elephant",16), bg="black", fg="white")
enjoy.grid(padx=5)
master.mainloop()
Please help me out, because I am a fresh starter in this topic.
Try something like this:
import tkinter as tk
def create_window(root):
# Create the new window
top = tk.Toplevel(root)
# Stop the user from interacting with the main window
top.grab_set()
root = tk.Tk()
menubar = tk.Menu(root)
menubar.add_command(label="Create new window", command=lambda: create_window(root))
root.config(menu=menubar)
root.mainloop()
It uses top.grab_set() to stop the user from interacting with the main window. It blocks all events until the user closes the pop up.
I am essentially trying to have my entry box display the entered text on the screen as a label, expect after each time the button is pressed (the button that displays the text), the newly entered data is displayed somewhere else on the screen. Essentially multiple labels from one entry box and button.
def writelabel():
labelentrval = Label(master, font = ("Helvetica", 15), text="" + str(entryvalue.get()))
labelentrval.place(x=645,y=621)
entryvalue.delete(first=0,last=22)
()
entryvalue = Entry(master)
entryvalue.place(x=700, y=515)
buttonpressy = Button(master,text="Enter", command=writelabel)
buttonpressy.place(x=845,y=510)
Code is above, and so far when I enter something into my entry box and press the button it displays it on the screen as a label. But how would I keep displaying my entries over and over in different places?
Thank you
You want to create a new label for every button press:
from tkinter import *
root = Tk()
def clicked():
text = e.get()
newLabel = Label(root, text=text)
newLabel.pack()
e = Entry(root)
e.pack()
b = Button(root, text='click', command=clicked)
b.pack()
root.mainloop()
I was wondering how I would add some sort of background text in the input box defined in the code attached here under:
The box could say "Example: Joe Bloggs" but greyed out and then remove when the user clicks inside the box? Hope this isn't too tricky.
# ************ Retrieve user's Full name ************
tk.Label(self, text='First and last name:').grid(sticky='e') # Label
self.full_name_entry = tk.Entry(self, bg='white', width=30) # Entry box
self.full_name_entry.grid(row=1, column=1, pady=15, columnspan=2) # Entry box placement
You need to:
use tk.Entry.insert to add the default text to an Entry widget
set the foreground color to 'grey'
upon the entry getting focus, the default is deleted, and the foreground set to 'black'.
you type in the text.
upon pressing return, the value of the entry is extracted, then the entry is reset with the default text in grey.
exiting the focus also resets the entry to default grey (you may want to choose avoid this as a partial entry will then be deleted if you make the entry lose focus; by clicking outside the box, for instance)
Here is what the code look like
import tkinter as tk
def handle_focus_in(_):
full_name_entry.delete(0, tk.END)
full_name_entry.config(fg='black')
def handle_focus_out(_):
full_name_entry.delete(0, tk.END)
full_name_entry.config(fg='grey')
full_name_entry.insert(0, "Example: Joe Bloggs")
def handle_enter(txt):
print(full_name_entry.get())
handle_focus_out('dummy')
root = tk.Tk()
label = tk.Label(root, text='First and last name:')
label.grid(sticky='e')
full_name_entry = tk.Entry(root, bg='white', width=30, fg='grey')
full_name_entry.grid(row=1, column=1, pady=15, columnspan=2)
full_name_entry.insert(0, "Example: Joe Bloggs")
full_name_entry.bind("<FocusIn>", handle_focus_in)
full_name_entry.bind("<FocusOut>", handle_focus_out)
full_name_entry.bind("<Return>", handle_enter)
root.mainloop()
Here is what it looks upon opening the window:
Upon giving focus to the Entry widget, the example text is deleted, and the font color changed to black; after filling the entry, the aspect is:
I am doing a GUI using for my code and finding it hard to develop what i want.
First ...
on the window an image and label appear and disappear after couple of seconds. after that a frame should arrive, followed by a menu option, when the menu option is selected it should disappear from frame and another image should appear.
self.gui = Tk()
def configure_window(self):
self.gui.geometry('700x500')
self.gui.resizable(height=False, width=False)
self.gui.update()
self.welcome_label()
self.welcome_image()
def welcome__image(self):
image = Image.open(image path)
photo = ImageTk.PhotoImage(image)
welcome_image = Label(master=self.gui, image=photo, justify='center',relief='raised')
welcome_image.image = photo
welcome_image.pack(padx=100, pady=100)
welcome_image.place(bordermode='outside', x=200,y=100)
welcome_image.after(ms=1000, func=welcome_image.place_forget)
def welcome_label(self):
welcome_label = Label(master=self.gui, text=welcome_label_text,font=welcome_label_font, justify='center',
state='active', fg='blue', anchor='center', pady=10, relief='raised' )
welcome_label.place(x=100, y=350)
welcome_label.after(ms=1000, func=welcome_label.place_forget)
def first_frame(self):
self.first_frame = LabelFrame( master = self.gui,text='Select First File',font= 'arial 10 bold underline', bg=self.background_colour,
height=200,width=690, bd=1, padx=5, pady=5)
self.first_frame.pack()
self.first_frame.place(x=0, y=0)
def select_button1(self):
self.file_open_button1 = Button(master=self.first_frame,text='...',state='disabled',command=self.cmd_file_select_button1)
when i run the code, welcome_image and welcome_frame places and forgets places after 1000 ms, but, first_frame also loads with parent widget. i want frame to arrive after the welcome_label disappears.
and the same sequence continues for LabelFrame
i have widgets in LabelFrame in which i have OptionMenu and button, i want optionMenu to disappear when user selects an option and another button should appear, same sequence in the button, button returns some sting and a label should appear in the place of button etc.
how to generate the sequence e.g. if an widget has place_forget() a sequence will be generated and another widget should be bind on that sequence. please help.
apology, if i am unable to make you understand my problem.
I'm making my own calculator using python and tkinter however I can't seem to find a way to change the value in the entry field. Let's say once the user taps the equal button, the value in the entry field changes to the answer of the user's equation. So how do you do it?
import Tkinter as tk
top = tk.Tk()
user_ent = tk.Entry(top, width='7', font='Verdana 50', justify='right')
user_ent.grid(columnspan='4')
button = tk.Button(top, text='clear', command=None) #button that clears the entry field
button.grid(column='0', row='1', columnspan='1')
top.mainloop()
How to you make the button clear the entry field once it's clicked
def solve():
txt = user_ent.get(0, tk.END)
user_ent.delete(0, tk.END)
user_ent.insert(tk.INSERT, eval(txt))
button = tk.Button(top, text='clear', command=solve)