I have a tkinter page that works by calling other tkinter pages, each with their own functions. When I call the page locally, the function works, but when it is called from the other page it doesn't work.
The function used to call the other page is this.
from tkinter import *
import subprocess
import tkinter.messagebox
import os.path
class meh:
def __init__ (self,root):
self.root =root
self.root.title("ODIN")
self.root.geometry("1350x750+0+0")
self.root.config(bg="ghost white")
def ap():
subprocess.call(["python.exe",r"C:\Users\felix\Documents\FelixPython\AttendancePageAdmin.py"])
#AttendancePage.Attendance(Tk())
MainFrame = Frame(self.root, bg="Ghost White")
MainFrame.grid()
CallButtonFrame = Frame(MainFrame, bd=2, width=1350, height=70, padx=18, pady=10, bg="blue2", relief = RIDGE)
CallButtonFrame.pack(side=TOP)
self.btnAttend = Button(CallButtonFrame, text = 'Attendance page' , font=('ariel',20,'bold'),height=1,width=10, bd=4, command = ap)
self.btnAttend.grid(row=0, column=0)
if __name__=='__main__':
root = Tk()
application = meh(root)
root.mainloop()
Related
I wrote the code, and need to display notifications at a user-specified time, but for some reason notifications are not displayed at the specified time, what's wrong?
I also tried to assign an int value to a variable, but alas, in this case an error was thrown
from tkinter import ttk
from tkinter import scrolledtext
import requests
import time
from tkinter import *
from tkinter import messagebox
def SiteCheck():
Site_Value = GetSiteBox.get("1.0", "end-1c")
Get_Response = requests.get(Site_Value)
if Get_Response.status_code != 200:
messagebox.showerror(title='Error', message=f"The website \"{Site_Value}\" dont work ")
else:
messagebox.showinfo(title="Successfully", message=f"The website \"{Site_Value}\" work")
time.sleep(TimeCh)
root = tk.Tk()
root.title("SITE CHECKER")
root.geometry('500x300')
ttk.Label(root, text="Enter link to verify",
font=("Times New Roman", 15)).grid(column=0, row=0)
GetSiteBox = scrolledtext.ScrolledText(root, wrap=tk.WORD,
width=57, height=11,
font=("Times New Roman", 12))
GetSiteBox.grid(column=0, row=2, pady=10, padx=10)
Check_Button = Button(
root,
command = SiteCheck,
text='Start checking',
)
Check_Button.grid(row=3, column=0)
TimeCheck = Entry(root,width=10)
TimeCheck.grid(column=0, row=1)
TimeCh = TimeCheck.get()
GetSiteBox.focus()
root.mainloop()
I'm currently programming a GUI using tkinter and Python 3.
My problem here is i made a Label with which i want to display the path of a file i opened via the askopenfilename() method and this path is not "generated" when i start the program, obviously, so the Label is empty which makes sense but i don't know how to fix it.
I'm gonna put the needed code below (I'm going to cut unnecessary code for this question):
import tkinter as tk
class Graphicaluserinterface(tk.Frame):
def __init__(self,master=None):
super().__init__(master)
self.grid()
self.fileopenname=tk.StringVar()
self.menubar = tk.Menu(self)
self.create_widgets()
def create_widgets(self):
self.inputpathdisplay = tk.Label(self,textvariable=self.fileopenname,bg="white",width=30)
self.inputpathdisplay.grid(row=1,column=8,columnspan=3,sticky = "W")
def fileopening(self):
from tkinter.filedialog import askopenfilename
self.fileopenname = askopenfilename(filetypes = [("binary files","*.bin*"),("all files","*.*")])
root = tk.Tk()
app = Graphicaluserinterface(master=root)
root.config(menu=app.menubar)
app.mainloop()
I read about using update_idletasks(). If this is correct in my case how would i go about implementing it here?
Right now you are doing self.fileopenname = askopenfilename() and this will redefine self.fileopenname as a string instead of a StringVar(). To correct this you need to set the value of StringVar with set().
That said you should also define all your imports at the top of your code instead of in your function.
import tkinter as tk
from tkinter.filedialog import askopenfilename
class Graphicaluserinterface(tk.Frame):
def __init__(self,master=None):
super().__init__(master)
self.grid()
self.fileopenname=tk.StringVar()
self.menubar = tk.Menu(self)
self.inputpathdisplay = tk.Label(self, textvariable=self.fileopenname, bg="white")
self.inputpathdisplay.grid(row=1,column=8,columnspan=3,sticky = "W")
self.fileopening()
def fileopening(self):
self.fileopenname.set(askopenfilename(filetypes = [("binary files","*.bin*"),("all files","*.*")]))
root = tk.Tk()
app = Graphicaluserinterface(master=root)
root.config(menu=app.menubar)
app.mainloop()
How can I create a Modal Dialogue Box by messagebox.showerror?
messagebox.showerror("Error", "No downloader.exe found")
When I create a messagebox, I found I can move the root windows.
and i need to create a Modal Dialogue Box like filedialog.askopenfilename.
filedialog.askopenfilename(initialdir = self.get_path()+ '/bin', filetypes=[("BIN Files", ".bin")])
here's the codes:
import tkinter
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import os
class Application(Frame):
def createWidgets(self, main_frame):
#self.llabel = Label(main_frame, text="Ready", width=20, bg="turquoise", font = ftLabel)
#self.llabel.grid(row=0, column=0, sticky=W+E) #columnspan=2
self.frame1 = Frame(main_frame)
self.frame1.grid(row=0, column=0, columnspan=2, sticky=W+E+N+S)
self.addr = StringVar()
self.addrtext = Entry(self.frame1, width=20, textvariable = self.addr)
self.addrtext.grid(row=0, column=0, sticky=W+E+N+S)
self.addr.set("0x0")
self.bfile = Button(self.frame1, text='BIN File', width=20)
self.bfile.grid(row=0, column=1, sticky=W+E+N+S)
messagebox.showerror("Error", "No downloader.exe found")
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack(fill=BOTH, expand=1)
main_frame = Frame(master)
main_frame.pack(fill="y", expand=1)
self.createWidgets(main_frame)
self.dl_thread = 0
if __name__=="__main__":
root = Tk()
#lock the root size
root.resizable(False,False)
app = Application(master=root)
app.mainloop()
I tried your code and messagebox.showerror is modal to me.
Maybe there is something else in your code (threads?) or maybe it's
dependent on your environment.
For reference, my entire code:
from tkinter import *
from tkinter import messagebox
root = Tk()
def do(): messagebox.showerror("Error", "No downloader.exe found")
b = Button(root, text='Dialog', command=do)
b.pack()
root.mainloop()
If that doesn't work you might want to take a look at: Tkinter messagebox not behaving like a modal dialog
I have tried EVERY " if name=='main' " suggestion and it still fails (or maybe I'm doing it wrong or not understanding it). I am also Not trying to run things from a command line. While testing things out in Pycharm, I am trying to get the main file to pop-up with a gui and then when I click on the button, trying to get the first window to go away and the second file/gui to pop up in its place.
Any help would be greatly appreciated.
this is the main one I am trying to start with but opens up with the second gui first
from tkinter import *
from tryingstuff import EmdMain
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
#firebutton
self.fphoto = PhotoImage(file="../icon/fireorig.png")
self.fbutton = Button(frame, image=self.fphoto)
self.fbutton.config( height=228, width=200)
self.fbutton.pack(side=LEFT)
#emsbutton
self.mphoto = PhotoImage(file="../icon/ems.png")
self.emsButton = Button(frame, image=self.mphoto, command=EmdMain)
self.emsButton.config( height=224, width=197)
self.emsButton.pack(side=RIGHT)
root = Tk()
root.title("ProQA Card set")
app = App(root)
root.mainloop()
This is the second file
from tkinter import *
def EmdMain():
frame = Frame()
frame.pack()
abdominalPnB = Button(frame, text="01_Abdominal Pain")
abdominalPnB.config(anchor="w", width=20, height=1)
abdominalPnB.grid(row=0, column=0)
root = Tk()
app = EmdMain()
root.mainloop()
if __name__=='__main__':
EmdMain()
I click on the button, but the progress bar is not moving. The batch file works perfectly though.
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from subprocess import call
def runBat():
p.start()
call ("mp3.bat")
root = Tk()
photobutton3 = PhotoImage(file="smile.png")
button3 = Button(root, image=photobutton3, command=runBat)
button3.grid()
p = ttk.Progressbar(root, orient=HORIZONTAL, length=200, mode='indeterminate')
p.grid()
root.mainloop()