I'm working on this project and I deiced to add a GUI interface. I have chosen to work with Tkinter cause I'm some sort familiar with Python. I'm running into the problem where I can run the GUI out of visual studio but I am unable to run the GUI off straight of my desktop. I have checked and there are no errors in my code. Can someone please help me fix the code.
This Is a snippet of the code which I am using to run the GUI
from tkinter import *
from tkinter.ttk import Progressbar
from tkinter import ttk
from tkinter import messagebox
import os
import shutil
from os import listdir
from os.path import isfile, join
import getpass
import time
window = Tk()
window.title("Move Files")
window.geometry('546x500')
def Movie():
TextBox.delete('1.0',END)
bar['value'] = 0
messagebox.showinfo('Message title', 'Message content')
def TVShow():
TextBox.delete('1.0',END)
bar['value'] = 0
TVShowMove()
#Buttons
Movie = Button(window,text='Move Movies', command=Movie, padx=50, pady=30)
Movie.place(x=40, y=40)
TVShow = Button(window,text='Move TV Shows', command=TVShow, padx=48, pady=30)
TVShow.place(x=300, y=40)
#Progressbar
bar = Progressbar(window, length=446, style='black.Horizontal.TProgressbar')
bar.place(x=40, y=140)
#TextBox
TextBox = Text(window, height=10, width=55)
TextBox.pack()
TextBox.place(x=40, y=170)
window.mainloop()
code is ok
i got this problem too!
try to open it from vscode itself
In Python 3.8 you cant import any of these.
from tkinter.ttk import Progressbar
from tkinter import ttk
from tkinter import messagebox
Instead, you have to import Tkinter as tk as seen below
from tkinter import *
import tkinter as tk
Related
In this program the window is in full, zoomed i would say, if i decrease the window and the maximize again the window on full and then i click the button, i notice that the filedialog opens first on the left and then it's placed immediately on the center, try a couple of times and you will notice this, i hope at least. How to place the filedialog directly on the center avoiding this "flickering" effect? Thanks
from tkinter import *
from PIL import Image, ImageTk
from tkinter import messagebox
from tkinter import filedialog
def jpg_png():
try:
file = filedialog.askopenfilename(initialdir='C:\\Users\\quaranta\\Desktop')
except AttributeError:
pass
win = Tk()
win.state('zoomed')
btn_apri_jpg_png = customtkinter.CTkButton(win,text='Apri file',text_font=('Courier',13),text_color='white',fg_color='#00A254',hover_color='#00AF54',width=10,corner_radius=8,command=jpg_png)
btn_apri_jpg_png.grid(row=0,column=2,pady=(20,0),padx=(0,50))
win.mainloop()
This might be a customtkinter issue
I tried recreating your problem without using customtkinter (as you stated in your comment to "not import it")
I can't reproduce your flickering with this code. Can you confirm that it still happens without using customtkinter?
from tkinter import *
from tkinter import filedialog
def jpg_png():
try:
file = filedialog.askopenfilename()
except AttributeError:
pass
win = Tk()
win.state('zoomed')
btn_apri_jpg_png = Button(win, text='Apri file', width=10, command=jpg_png)
btn_apri_jpg_png.grid(row=0, column=2, pady=(20, 0), padx=(0, 50))
win.mainloop()
Hello everyone how can insert in gui text function result of another module. you can see code below:
modul_1.py
import tkinter as tk
from tkinter import *
import modul_2
window = tk.Tk()
b = Button(text="çalıştır", command = modul_2.goster)
b.place(x=20, y=20)
window.mainloop()
modul_2.py
import tkinter as tk
from tkinter import messagebox
import modul_1
def goster():
messagebox.showinfo("deneme","deneme")
Text1 = tk.Text(window)
Text1.insert(tk.END, "Bu kısım")
Text1.place(x=50, y=50)
goster()
The better way is to stock the data from the module you want then import it in the desired module .
I'm trying to add the ScrolledText widget to a Tkinter window. The program reads it perfectly as in it accepts the INSERT method for it with no errors but it's not showing up. The problem came up when I added Notebook Tabs. I've attached the code snippet. I used the place() method because I need the rest of my buttons and labels arranged in a specific pattern.
import tkinter
from tkinter import *
from tkinter import scrolledtext
from tkinter import messagebox
from tkinter import ttk
import os
import datetime
# Variables
window = Tk()
window.title("Vesnica Pomenire")
window.geometry('1500x1000')
var = IntVar()
var.set(1)
txt = scrolledtext.ScrolledText(window,width=40,height=10)
txt.place(x=50, y=50)
You're missing the mainloop()
import tkinter
from tkinter import *
from tkinter import scrolledtext
from tkinter import messagebox
from tkinter import ttk
import os
import datetime
# Variables
window = Tk()
window.title("Vesnica Pomenire")
window.geometry('1500x1000')
var = IntVar()
var.set(1)
txt = scrolledtext.ScrolledText(window,width=40,height=10)
txt.place(x=50, y=50)
window.mainloop() #You are missing this
You can read more about mainloop() here
You really missed mainloop command
window.mainloop()
add this at the bottom of your code and it will do the thing
So I am making a project that outputs responses from Google Sheets that asks me and gives me video ideas. I just need help figuring out how to make Tkinter output the whole response into a window.
Here is the main code for the project I am working on:
import pygsheets
import random
import tkinter
import numpy as np
gc = pygsheets.authorize()
sh = gc.open('Give Me Video Ideas (Responses)')
wks = sh.sheet1
for row in wks:
print(list(row))
And here is the Tkinter code I have so far:
import sys
import os
from tkinter import *
window=Tk()
window.title("Give me Video Ideas")
window.geometry('550x200')
def run():
os.system('python anothergithub.py')
btn = Button(window, text="Click Me", bg="black", fg="white",command=run)
btn.grid(column=0, row=0)
window.mainloop()
This is if you have variables in you deal line run(string)
import sys
import os
from tkinter import *
window=Tk()
window.title("Give me Video Ideas")
window.geometry('550x200')
def run():
os.system('python anothergithub.py')
btn = Button(window, text="Click Me", bg="black", fg="white",command=lambda: run("Hey"))
btn.grid(column=0, row=0)
window.mainloop()
I am using tkinter asopenfilename to trigger a file chooser so as to read files from my local directory. My problem is that after the file is chosen, the window freezes and python is 'not responding'.
I've tried the answer from this post: Tkinter askopenfilename() won't close no luck.
Below is my code:
from tkinter import Tk
from tkinter.filedialog import askopenfilename
root = Tk()
root.withdraw()
root.update()
filename = askopenfilename()
print(filename)
Is there anything that I am missing? Let me know if you need more clarity. Thanks!
I tried all above solutions but didn't seem to solve the same issue for me. The dialog box was opening but somewhere in the background.
Found this code elsewhere and it works like a charm for me. On windows 10 too, python 3.x, and using Jupyter Notebook.
Posting it here in case it could help others.
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
root.call('wm', 'attributes', '.', '-topmost', True)
file_path = filedialog.askopenfilename(
%gui tk
print(file_path)
I tried using root.update() after filename = askopenfilename() in my MacOS.
Following worked for me-
from tkinter import Tk
from tkinter.filedialog import askopenfilename
root = Tk()
root.withdraw()
filename = askopenfilename()
root.update()
print(filename)
I had the same behavior on MacOS and adding the iPython magic %gui tk appears to be solving the issue:
from tkinter import Tk
from tkinter.filedialog import askopenfilename
%gui tk
root = Tk()
root.withdraw()
filename = askopenfilename(multiple=True)
print(filename)
From the docs:
%gui tk # enable Tk event loop integration
askopenfilename doesn't work in windows
from tkinter import *
#from tkFileDialog import askopenfilename
import tkinter.filedialog
def callback():
name= tkinter.filedialog.askopenfilenames()
print (name)
errmsg = 'Error!'
Button(text='File Open', command=callback).pack(fill=X)
mainloop()