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
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 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
I want to make a Tkinter interface for a program I just wrote. The interface needs to have a widget where the user can insert an image for the program to process. I couldn't find such a widget online. How would I make such an interface?
Below is an example of tkinter entry widget that takes in images right away:
try: # In order to be able to import tkinter for
import tkinter as tk # either in python 2 or in python 3
import tkinter.filedialog as tkfd
except ImportError:
import Tkinter as tk
import tkFileDialog as tkfd
if __name__ == '__main__':
root = tk.Tk()
entry = tk.Entry(root)
entry.pack()
path = tkfd.askopenfilename(initialdir = "/", title = "Select file",
filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
entry.insert('0', path)
root.mainloop()
import Tkinter
window=Tk()
msg1='abc'
msg2='def'
label =Label(window,text=(msg1,msg2), fg='blue')
label.grid(row=0,column=1)
window.mainloop()
output is {abc}{def} I want output as abcdef. how to do that?
You're writing text=(msg1,msg2) with (msg1,msg2) being a list.
Just change it to msg1+msg2
And this code cannot work, you can't create a Tk() if you import Tkinter like that.
Change it to from Tkinter import *