remove {} from Tkinter label - python

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 *

Related

Why Filedialogs opens on two differents places?

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()

Python guı text insert function result

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 .

Tkinter ScrolledText widget not appearing

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

how to make modern button in tkinter

I want to have abutton like this in tkinter (Modern window 10 buttons):
However, I get this button:
The code for my button is:
from tkinter import Tk,Button
root=Tk()
Button(root,text='OK').pack()
Another alternative to create button is to create a label and bind it to the action functions. In the below example .bind() is used to connect the label with respective function. You can design according to your requirements.
from tkinter import *
def OnPressed(event):
print('Hello')
def OnHover(event):
But.config(bg='red', fg='white')
def OnLeave(event):
But.config(bg='white', fg='black')
root = Tk()
But = Label(root, text='Hi', bg='white', relief='groove')
But.place(x=10, y=10, width=100)
But.bind('<Button-1>', OnPressed)
But.bind('<Enter>', OnHover)
But.bind('<Leave>', OnLeave)
root.mainloop()
The themed widgets are in 'themed Tk' aka ttk.
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
ok = ttk.Button(root, text='OK')
ok.pack()
root.mainloop()
Avoid from tkinter import * as both tkinter and tkinter.ttk define Button and many other widgets.
If you use this on Windows you should get something looking like a native button. But this is a theme and can be changed. On Linux or MacOS you will get a button style that is appropriate to that platform.
vol_up = Button(root, text="+",activebackground='orange',bg='yellow')
vol_up.pack(side='top')

Tkinter Gui Not running when .py file is opened

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

Categories