Python
 Computer >> コンピューター >  >> プログラミング >> Python

PythonTkinterを使用してMessageBoxの位置を変更する方法


tkinterを使用してダイアログボックスを作成するとします。ダイアログボックスを作成するには、いくつかの関数を含むMessageBoxライブラリを使用して、ダイアログタイプをすばやく作成できます。

作成されたダイアログボックスの位置を調整するには、基本的に現在のボックスを優先し、他のすべてのプロセスをバックエンドに保持する「トップレベル」プロパティを使用できます。

タイトル、メッセージ、詳細など、その他の機能が含まれています。 MessageBoxウィジェットの位置を変更するには、ジオメトリを使用します メソッド。

#import the tkinter library

from tkinter import *

#define the messagebox function
def messagebox():

#toplevel function creates MessageBox dialog which appears on top of the screen
   top=Toplevel(win)
   top.title("Click Me")
   #Define the position of the MessageBox
   x_position = 600
   y_position = 400
   top.geometry(f"600x200+{x_position}+{y_position}")
   #Define the property of the messageBox
   l1=Label(top, text= "Hello! TutorialsPoint",bg= "green", fg=
"white",font=('Times New Roman', 24),height=50, width= 50).pack()

#Create an instance of the tkinter frame
#And resize the frame
win = Tk()
win.geometry("600x200")
win.title("Window-1")
Button(win, text="Click Me", command=messagebox,
width=8).pack(pady=80)

win.mainloop()

出力

上記のコードを実行すると、次の出力ウィンドウが生成されます。

PythonTkinterを使用してMessageBoxの位置を変更する方法

[クリックしてください]ボタンをクリックすると、後で配置できる次のダイアログボックスが開きます。

PythonTkinterを使用してMessageBoxの位置を変更する方法


  1. Tkinterでフレームの背景を変更するにはどうすればよいですか?

    tkinterフレームの背景色と前景色を変更するために、 bgに異なる値を割り当てることができます。 およびfg フレームのパラメータ 機能。 例 この例では、背景色が異なる2つのフレームを作成しました。 #Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("650x250") #Create an frame frame1= Frame(w

  2. Python Tkinter –ラベルウィジェットのテキストサイズを変更するにはどうすればよいですか?

    Tkinterラベルウィジェットは、ウィンドウにラベルを作成するために使用されます。 tkinter.ttkパッケージを使用してウィジェットのスタイルを設定できます。 Labelウィジェットのfont-size、font-family、およびfont-styleのサイズを変更するには、 font(‘font-family font style’、font-size)の組み込みプロパティを使用できます。 。 例 この例では、font-sizeやfont-styleなどのラベルテキストのスタイルを変更するボタンを作成します。 #Import the required libraries from